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. Returns the object matching the given lookup parameters
none()
filter
when you add new apps to INSTALLED_APPS
get(**kwargs)
2. These add custom "row-level" functionality to your objects. These act on a particular model instance.
latest(field_name=None)
Custom model methods
OneToOneField
Q(question__istartswith='What')
3. Returns a dictionary of aggregate values (averages - sums - etc) calculated over the QuerySet. Each argument to this method specifies a value that will be included in the dictionary that is returned.
only(*fields)
range
aggregate(args - *kwargs)
Custom model methods
4. 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.
slicing
ForeignKey
filter(**kwargs)
exact
5. When to run syncdb
primary_key
only(*fields)
when you add new apps to INSTALLED_APPS
class type
6. Lookup type that returns results that fall into an inclusive date range.
Field lookups
Meta class
class attributes
range
7. This query deletes all Entry objects with a pub_date year of 2005.
distinct()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
MultipleObjectsReturned
Entry.objects.filter(pub_date__year=2005).delete()
8. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
Meta class
update()
clear() method
istartswith
9. This gives your model metadata.
iregex
Meta class
filter(**kwargs)
values(*fields)
10. 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.
get_absolute_url()
reverse()
choices tuple
update()
11. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
default
all()
Entry.objects.filter(pub_date__year=2005).delete()
~
12. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
defer(*fields)
distinct()
endswith
month
13. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Field lookups
endswith
iteration
14. The default for this is the name of the child class followed by '_set'.
reverse name
regex
gt
values_list(*fields)
15. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.
values_list(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
create(**kwargs)
defer(*fields)
16. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Field lookups
unique
Proxy model
one-to-one relationship
17. Lookup type that yields a case-insensitive match.
iexact
distinct()
one-to-one relationship
order_by(*fields)
18. 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
when you add new apps to INSTALLED_APPS
startswith
select_related()
F()
19. In some complex data-modeling situations - your models might contain a lot of fields - some of which could contain a lot of data (for example - text fields) - or require expensive processing to convert them to Python objects. If you are using the res
slicing
Entry.objects.filter(pub_date__range=(start_date - end_date))
defer(*fields)
add()
20. 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
ordered
intermediate models
many-to-many relationship
lte
21. 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
22. Defined by django.db.models.ForeignKey. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-one relationship
pickling
select_related()
lt
23. 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
&
count()
annotate(args - *kwargs)
iregex
24. These methods are intended to do "table-wide" things.
unique
Entry.objects.filter(pub_date__year=2005).delete()
Manager methods
filter chaining
25. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
OneToOneField
many-to-many relationship
Q(question__istartswith='What')
26. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
help_text
QuerySet
Entry.objects.filter(id__gt=4)
in
27. Fields are specified by these
filter(**kwargs)
class attributes
in_bulk(id_list)
when you add new apps to INSTALLED_APPS
28. a QuerySet can be sliced - using Python's array-slicing syntax.
Entry.objects.filter(pub_date__year=2005).delete()
slicing
relationship spanning
Meta class
29. (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.
pickling
clear() method
iexact
Restrictions on field names
30. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
when you add new apps to INSTALLED_APPS
filter chaining
startswith
relationship spanning
31. Lookup type that returns results with a case-sensitive start sequence.
choices
endswith
dates(field - kind - order='ASC')
startswith
32. This model method is used for updating a ManyToManyField.
exact
add()
dates(field - kind - order='ASC')
values(*fields)
33. Lookup type that returns results less than a given value.
pk
Model metadata
Many-to-many relationship to self
lt
34. Can be used to remove all many-to-many relationships for an instance
get_or_create(**kwargs)
Entry.objects.filter(id__in=[1 - 3 - 4])
clear() method
Abstract base class
35. 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
36. 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
distinct()
year
OneToOneField
F()
37. 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.
in_bulk(id_list)
model
|
Abstract base class
38. Lookup type that finds a case-insensitive regular expression match.
iregex
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Q()
startswith
39. 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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
exists()
create(**kwargs)
40. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Abstract base class
Field lookups
__unicode__()
41. 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
exact
pickling
choices tuple
42. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
isnull
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
get(**kwargs)
endswith
43. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
MultipleObjectsReturned
update(**kwargs)
dates(field - kind - order='ASC')
44. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
iteration
order_by(*fields)
class attributes
45. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
values(*fields)
Field lookups
all()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
46. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
through argument
values_list(*fields)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
47. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary
get_or_create(**kwargs)
Field lookups
choices
only(*fields)
48. 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.
F()
endswith
Q()
reverse()
49. If this option is True - Django will store empty values as NULL in the database. Default is False.
Proxy model
null
iregex
intermediate models
50. 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.
filter chaining
iterator()
QuerySet
Q(question__startswith='Who') | ~Q(pub_date__year=2005)