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. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
update(**kwargs)
only(*fields)
relationship spanning
2. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
choices
month
iregex
Many-to-many relationship through an intermediate model
3. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
save()
get(**kwargs)
filter
values(*fields)
4. 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
gt
intermediate models
select_related()
Abstract base class
5. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
class type
help_text
day
6. Lookup type for date/datetime fields that finds a 'day of the week' match.
evaluation
week_day
Q(question__istartswith='What')
delete()
7. This field is added automatically - but this behavior can be overridden
Entry.objects.filter(pub_date__range=(start_date - end_date))
latest(field_name=None)
range
id field
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.
OneToOneField
iterator()
relationship spanning
update()
9. Lookup type that yields a case-insensitive match.
isnull
values(*fields)
iexact
Multi-table inheritance
10. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
get_absolute_url()
Manager
delete()
iteration
11. 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)
istartswith
OneToOneField
Model metadata
relationship spanning
12. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
~
contains
default
13. (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
startswith
Restrictions on field names
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
14. Lookup type that returns results less than or equal to a given value.
gt
lte
lt
Restrictions on field names
15. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
gt
delete()
==
Entry.objects.filter(id__in=[1 - 3 - 4])
16. These methods are intended to do "table-wide" things.
Q(question__istartswith='What')
db
Manager methods
all()
17. If True - this field is the primary key for the model.
primary_key
values(*fields)
delete()
one-to-one relationship
18. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
iregex
MultipleObjectsReturned
many-to-many relationship
search
19. 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.
none()
ManyToManyField
reverse()
search
20. This model type is useful if you only want to modify the Python-level behavior of a model - without changing the models fields in any way. This creates a stand-in for the original model. You can create - delete and update instances of this new model
exact
Q(question__istartswith='What')
Proxy model
__unicode__()
21. This query finds all entries with an id greater than 4.
gte
week_day
aggregate(args - *kwargs)
Entry.objects.filter(id__gt=4)
22. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Many-to-many relationship to self
Manager
default
get_or_create(**kwargs)
23. This query deletes all Entry objects with a pub_date year of 2005.
db
Entry.objects.filter(pub_date__year=2005).delete()
filter
get(**kwargs)
24. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
choices
one-to-one relationship
lte
evaluation
25. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
through argument
values(*fields)
Field lookups
lt
26. This model method is used for updating a ManyToManyField.
Entry.objects.filter(id__gt=4)
add()
__unicode__()
Many-to-many relationship through an intermediate model
27. 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
many-to-one relationship
annotate(args - *kwargs)
exact
through argument
28. A Python "magic method" that returns a unicode "representation" of any object.
null
__unicode__()
lte
id field
29. Lookup type that finds a case-sensitive regular expression match.
pk
regex
intermediate models
Entry.objects.filter(id__in=[1 - 3 - 4])
30. Fields are specified by these
aggregate(args - *kwargs)
default
class attributes
regex
31. By default - results returned by a QuerySet are ordered by the ordering tuple given by the ordering option in the model's Meta. You can override this on a per-QuerySet basis by using the this method.
order_by(*fields)
filter(**kwargs)
in_bulk(id_list)
Manager methods
32. Returns a new QuerySet containing objects that match the given lookup parameters.
DoesNotExist
filter(**kwargs)
one-to-one relationship
filter
33. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
null
reverse()
exclude(**kwargs)
34. 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
35. 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.
__unicode__()
relationship spanning
Entry.objects.filter(id__gt=4)
ForeignKey
36. This query finds all entries between a start date of start_date and an end date of end_date.
class attributes
choices
latest(field_name=None)
Entry.objects.filter(pub_date__range=(start_date - end_date))
37. This method immediately deletes the object and has no return value.
delete()
save()
many-to-one relationship
choices tuple
38. 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.
model
&
choices
exact
39. 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
40. Keyword shortcut for looking up an object by primary key.
in
when you add new apps to INSTALLED_APPS
pk
clear() method
41. 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.
get_absolute_url()
month
save()
QuerySet
42. Defines a one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.
OneToOneField
Q()
default
choices
43. 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
id field
select_related()
all()
class type
44. Manager method used to retrieve every object in a model.
all()
delete()
QuerySet
Entry.objects.filter(id__in=[1 - 3 - 4])
45. The database that will be used if this query is executed now
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
db
pickling
reverse()
46. 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.
aggregate(args - *kwargs)
filter chaining
in
lt
47. 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
slicing
exact
Entry.objects.filter(pub_date__year=2005).delete()
F()
48. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
aggregate(args - *kwargs)
startswith
49. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
Entry.objects.filter(pub_date__range=(start_date - end_date))
get(**kwargs)
Multi-table inheritance
Custom model methods
50. Returns the object matching the given lookup parameters
get(**kwargs)
save()
contains
Manager