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. Lookup type that returns results that fall into an inclusive date range.
add()
all()
defer(*fields)
range
2. These methods are intended to do "table-wide" things.
related_name
Manager methods
update()
latest(field_name=None)
3. 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
values_list(*fields)
regex
Meta class
annotate(args - *kwargs)
4. Lookup type that returns results with a case-insensitive end sequence.
iendswith
null
blank
exists()
5. Lookup type that returns results greater than or equal to a given value.
select_related()
in
ManyToManyField
gte
6. 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
add()
gte
7. 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.
null
aggregate(args - *kwargs)
gt
all()
8. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
distinct()
choices
evaluation
month
9. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
in_bulk(id_list)
==
when you add new apps to INSTALLED_APPS
10. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.
Many-to-many relationship to self
dates(field - kind - order='ASC')
order_by(*fields)
related_name
11. 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.
slicing
__unicode__()
Meta class
choices tuple
12. 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
filter
slicing
Many-to-many relationship through an intermediate model
only(*fields)
13. Disjunction operator for Q objects.
reverse()
choices
range
|
14. Lookup type that returns results in a given list.
in
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
values(*fields)
get_absolute_url()
15. Lookup type that returns results with a case-sensitive start sequence.
startswith
search
values(*fields)
gte
16. 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
class type
in_bulk(id_list)
range
relationship spanning
17. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
startswith
get(**kwargs)
choices
distinct()
18. 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
Meta class
DoesNotExist
Entry.objects.filter(pub_date__range=(start_date - end_date))
exists()
19. This query deletes all Entry objects with a pub_date year of 2005.
filter chaining
Entry.objects.filter(pub_date__year=2005).delete()
in
QuerySet
20. This method returns tuples of values when iterated over. Each tuple contains the value from the respective field passed into the call to this method -- so the first item is the first field - etc.
exists()
when you add new apps to INSTALLED_APPS
values_list(*fields)
Manager methods
21. If True - the table does not permit duplicate values for this field.
unique
Manager methods
class type
get_or_create(**kwargs)
22. This method immediately deletes the object and has no return value.
get_absolute_url()
slicing
Manager methods
delete()
23. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
annotate(args - *kwargs)
Model metadata
year
24. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
all()
Proxy model
isnull
Restrictions on field names
25. 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
exact
select_related()
many-to-one relationship
Q()
26. Lookup type for date/datetime fields that finds an exact day match.
day
get_absolute_url()
values(*fields)
add()
27. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
filter chaining
endswith
iteration
through argument
28. To activate your models
reverse name
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
slicing
lte
29. 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.
help_text
Q(question__istartswith='What')
update()
Many-to-many relationship to self
30. a QuerySet can be sliced - using Python's array-slicing syntax.
Manager methods
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
slicing
gt
31. This represents a collection of objects from your database. It can have zero - one or many filters.
none()
Field lookups
QuerySet
Proxy model
32. 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.
ForeignKey
slicing
ordered
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
33. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
add()
==
filter(**kwargs)
endswith
34. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
Q(question__istartswith='What')
using(alias)
Field lookups
35. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
ManyToManyField
Q()
using(alias)
related_name
36. Lookup type that finds a case-sensitive regular expression match.
regex
Manager methods
Entry.objects.filter(id__gt=4)
only(*fields)
37. (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.
null
Abstract base class
Restrictions on field names
year
38. This query uses an F object to increment the pingback count for every entry in the blog.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
39. 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.
Meta class
filter chaining
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
gt
40. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
pk
evaluation
null
41. If True - this field is the primary key for the model.
iteration
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
primary_key
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
42. A convenience method for constructing an object and saving it all in one step.
Proxy model
create(**kwargs)
save()
get_absolute_url()
43. 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.
pk
QuerySet
delete()
default
44. An iterable (e.g. - a list or tuple) of 2-tuples to use as options for this field. If this is given - Django's admin will use a select box instead of the standard text field and will limit options to those given.
iteration
update()
save()
choices
45. This query finds all entries with an id in the list [1 - 3 - 4]
select_related()
MultipleObjectsReturned
help_text
Entry.objects.filter(id__in=[1 - 3 - 4])
46. This tells Django how to calculate the URL for an object. Django uses this in its admin interface - and any time it needs to figure out a URL for an object.
choices
using(alias)
get_absolute_url()
iteration
47. 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.
get_or_create(**kwargs)
exclude(**kwargs)
reverse name
exact
48. Returns the most recent object in the table - by date - using the field_name provided as the date field.
evaluation
Custom model methods
in_bulk(id_list)
latest(field_name=None)
49. A convenience method for looking up an object with the given kwargs - creating one if necessary.
db
day
get_or_create(**kwargs)
clear() method
50. When to run syncdb
id field
Meta class
when you add new apps to INSTALLED_APPS
add()