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. 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
all()
&
__unicode__()
F()
2. 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
select_related()
exists()
defer(*fields)
many-to-one relationship
3. 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.
F()
==
Many-to-many relationship to self
Model metadata
4. Can be used to remove all many-to-many relationships for an instance
delete()
clear() method
in
reverse name
5. Lookup type for date/datetime fields that finds a 'day of the week' match.
ForeignKey
day
iterator()
week_day
6. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
exclude(**kwargs)
month
istartswith
one-to-one relationship
7. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
update()
reverse()
distinct()
8. 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
many-to-many relationship
select_related()
|
F()
9. 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
help_text
annotate(args - *kwargs)
when you add new apps to INSTALLED_APPS
using(alias)
10. 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.
Multi-table inheritance
clear() method
reverse()
default
11. Lookup type that returns results greater than a given value.
gt
endswith
in
default
12. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
class type
regex
evaluation
13. These add custom "row-level" functionality to your objects. These act on a particular model instance.
blank
Custom model methods
values(*fields)
order_by(*fields)
14. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
gt
Entry.objects.filter(id__in=[1 - 3 - 4])
get(**kwargs)
year
15. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
filter(**kwargs)
many-to-many relationship
when you add new apps to INSTALLED_APPS
QuerySet
16. Conjuntion operator for Q objects.
&
clear() method
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
model
17. Defines a many-to-many relationship. You use it just like any other Field type: by including it as a class attribute of your model.
range
startswith
class attributes
ManyToManyField
18. If True - this field is the primary key for the model.
iexact
Manager methods
ordered
primary_key
19. 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()
evaluation
order_by(*fields)
values_list(*fields)
iregex
20. 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.
one-to-one relationship
get_or_create(**kwargs)
in_bulk(id_list)
pickling
21. This query finds all entries between a start date of start_date and an end date of end_date.
through argument
Manager methods
Entry.objects.filter(pub_date__range=(start_date - end_date))
using(alias)
22. 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.
create(**kwargs)
update()
slicing
aggregate(args - *kwargs)
23. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
iexact
primary_key
many-to-many relationship
related_name
24. Lookup type that returns results with a case-insensitive end sequence.
exclude(**kwargs)
using(alias)
iendswith
create(**kwargs)
25. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
aggregate(args - *kwargs)
Manager methods
MultipleObjectsReturned
==
26. This field is added automatically - but this behavior can be overridden
Entry.objects.filter(id__in=[1 - 3 - 4])
id field
filter
get_or_create(**kwargs)
27. 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.
choices
pk
iteration
unique
28. Lookup type that finds a case-sensitive regular expression match.
Custom model methods
annotate(args - *kwargs)
Abstract base class
regex
29. 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.
gt
latest(field_name=None)
evaluation
search
30. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
lt
31. Disjunction operator for Q objects.
month
|
unique
Proxy model
32. 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.
create(**kwargs)
Multi-table inheritance
save()
Model metadata
33. Lookup type that yields a case-insensitive match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
delete()
iexact
get_absolute_url()
34. 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.
month
Entry.objects.filter(id__in=[1 - 3 - 4])
OneToOneField
only(*fields)
35. Returns a new QuerySet containing objects that match the given lookup parameters.
latest(field_name=None)
pk
filter(**kwargs)
range
36. 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_absolute_url()
order_by(*fields)
only(*fields)
in
37. 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.
reverse name
many-to-one relationship
iendswith
latest(field_name=None)
38. Manager method used to retrieve every object in a model.
Entry.objects.filter(id__in=[1 - 3 - 4])
filter
all()
reverse()
39. 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)
add()
istartswith
Many-to-many relationship to self
40. This is a criterion that narrow down a QuerySet based on given parameters.
through argument
in_bulk(id_list)
filter
endswith
41. 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
Proxy model
Meta class
in_bulk(id_list)
distinct()
42. 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.
choices tuple
in_bulk(id_list)
intermediate models
all()
43. This model method saves a model instance to the database. This method has no return value.
many-to-many relationship
pickling
order_by(*fields)
save()
44. 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
45. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
QuerySet
Field lookups
istartswith
46. 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.
delete()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Model metadata
only(*fields)
47. 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
48. 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
==
through argument
iteration
Many-to-many relationship to self
49. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
intermediate models
month
exclude(**kwargs)
50. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
count()
exclude(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
Model metadata