SUBJECTS
|
BROWSE
|
CAREER CENTER
|
POPULAR
|
JOIN
|
LOGIN
Business Skills
|
Soft Skills
|
Basic Literacy
|
Certifications
About
|
Help
|
Privacy
|
Terms
|
Email
Search
Test your basic knowledge |
Django Queryset
Start Test
Study First
Subject
:
it-skills
Instructions:
Answer 50 questions in 15 minutes.
If you are not ready to take this test, you can
study here
.
Match each statement with the correct term.
Don't refresh. All questions and answers are randomly picked and ordered every time you load a test.
This is a study tool. The 3 wrong answers for each question are randomly chosen from answers to other questions. So, you might find at times the answers obvious, but you will see it re-enforces your understanding as you take the test each time.
1. Disjunction operator for Q objects.
all()
|
QuerySet
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
2. Lookup type that returns results less than or equal to a given value.
lte
month
search
~
3. Lookup type for date/datetime fields that finds a 'day of the week' match.
Manager
week_day
delete()
regex
4. To activate your models
OneToOneField
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
model
pk
5. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)
day
Model metadata
ForeignKey
exists()
6. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th
exists()
startswith
__unicode__()
Many-to-many relationship through an intermediate model
7. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
Manager methods
class attributes
annotate(args - *kwargs)
in_bulk(id_list)
8. This query finds all entries between a start date of start_date and an end date of end_date.
latest(field_name=None)
Entry.objects.filter(pub_date__range=(start_date - end_date))
default
defer(*fields)
9. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
update()
many-to-many relationship
null
get(**kwargs)
10. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()
exclude(**kwargs)
evaluation
search
Q(question__istartswith='What')
11. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.
class type
reverse()
get_absolute_url()
intermediate models
12. Lookup type that yields an "exact" match. If you don't provide a lookup type -- that is - if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be of this sort.
exact
&
values(*fields)
class type
13. This gives your model metadata.
model
ordered
Meta class
intermediate models
14. a QuerySet can be sliced - using Python's array-slicing syntax.
year
slicing
gte
Entry.objects.filter(pub_date__year=2005).delete()
15. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
select_related()
iendswith
null
through argument
16. (1) These cannot be Python reserved words - because that would result in a Python syntax error. (2) These cannot contain more than one underscore in a row - due to the way Django's query lookup syntax works.
iexact
Restrictions on field names
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
17. Lookup type that returns results with a case-sensitive start sequence.
startswith
range
ManyToManyField
Manager
18. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
19. If True - the table does not permit duplicate values for this field.
delete()
unique
get_absolute_url()
help_text
20. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
values(*fields)
model
Entry.objects.filter(pub_date__year=2005).delete()
21. This model method saves a model instance to the database. This method has no return value.
distinct()
choices tuple
save()
values(*fields)
22. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
23. Conjuntion operator for Q objects.
&
get_or_create(**kwargs)
Manager
reverse()
24. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Many-to-many relationship through an intermediate model
blank
in_bulk(id_list)
25. This model method is used for updating a ManyToManyField.
iregex
distinct()
QuerySet
add()
26. Adds to each object in the QuerySet with the provided list of aggregate values (averages - sums - etc) that have been computed over the objects that are related to the objects in the QuerySet. Each argument to this is content that will be added to ea
distinct()
annotate(args - *kwargs)
filter
primary_key
27. The default for this is the name of the child class followed by '_set'.
all()
Custom model methods
reverse name
istartswith
28. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
exact
iteration
count()
exclude(**kwargs)
29. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode
Abstract base class
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
OneToOneField
create(**kwargs)
30. The first element in this iterable is the value that will be stored in the database - the second element will be displayed by the admin interface - or in a ModelChoiceField.
Model metadata
choices tuple
pk
regex
31. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
year
gte
F()
==
32. Defines a many-to-one relationship. ou use it just like any other Field type: by including it as a class attribute of your model.
ForeignKey
through argument
Field lookups
search
33. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
filter chaining
Many-to-many relationship through an intermediate model
using(alias)
34. Can be used to remove all many-to-many relationships for an instance
QuerySet
annotate(args - *kwargs)
clear() method
only(*fields)
35. Used to get a QuerySet for a model. This is called 'objects' by default.
pickling
Manager
Meta class
evaluation
36. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used
Q()
slicing
exclude(**kwargs)
class type
37. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
all()
help_text
many-to-many relationship
ManyToManyField
38. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
primary_key
related_name
create(**kwargs)
39. Returns a DateQuerySet -- a QuerySet that evaluates to a list of datetime.datetime objects representing all available dates of a particular kind within the contents of the QuerySet.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
40. Fields are specified by these
class attributes
MultipleObjectsReturned
Entry.objects.filter(pub_date__range=(start_date - end_date))
many-to-many relationship
41. Lookup type that finds a case-insensitive regular expression match.
iregex
in_bulk(id_list)
aggregate(args - *kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
42. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
get(**kwargs)
create(**kwargs)
iexact
43. If True - this field is the primary key for the model.
primary_key
istartswith
gte
search
44. A Python "magic method" that returns a unicode "representation" of any object.
pk
__unicode__()
ForeignKey
defer(*fields)
45. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
help_text
order_by(*fields)
distinct()
46. Specifies the model that will be used to govern the many-to-many relationship. You can then put extra fields on the intermediate model. The intermediate model is associated with the ManyToManyField using this to point to the model that will act as an
exists()
get(**kwargs)
save()
through argument
47. Lookup type that tests for inclusion in a case-sensitive fashion.
class attributes
one-to-one relationship
iterator()
contains
48. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
unique
db
intermediate models
filter(**kwargs)
49. Lookup type that returns results that fall into an inclusive date range.
Many-to-many relationship through an intermediate model
range
values_list(*fields)
blank
50. This represents a collection of objects from your database. It can have zero - one or many filters.
range
through argument
Field lookups
QuerySet