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. 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.
startswith
month
order_by(*fields)
select_related()
2. 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.
Manager methods
values_list(*fields)
contains
filter(**kwargs)
3. Lookup type that yields a case-insensitive match.
Field lookups
iexact
delete()
contains
4. A convenience method for constructing an object and saving it all in one step.
select_related()
null
ordered
create(**kwargs)
5. 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
&
in
annotate(args - *kwargs)
6. This query deletes all Entry objects with a pub_date year of 2005.
QuerySet
slicing
OneToOneField
Entry.objects.filter(pub_date__year=2005).delete()
7. These methods are intended to do "table-wide" things.
Manager methods
in
one-to-one relationship
exact
8. 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
intermediate models
filter chaining
through argument
&
9. Returns a new QuerySet containing objects that match the given lookup parameters.
ordered
only(*fields)
filter(**kwargs)
annotate(args - *kwargs)
10. 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()
delete()
many-to-one relationship
choices
11. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
==
startswith
exclude(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
12. To activate your models
range
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
many-to-one relationship
iexact
13. If True - the table does not permit duplicate values for this field.
isnull
Q()
unique
iendswith
14. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
ordered
filter
select_related()
15. When to run syncdb
search
blank
pickling
when you add new apps to INSTALLED_APPS
16. a QuerySet can be sliced - using Python's array-slicing syntax.
Entry.objects.filter(id__gt=4)
OneToOneField
iendswith
slicing
17. 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.
delete()
F()
endswith
in_bulk(id_list)
18. 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
F()
in_bulk(id_list)
defer(*fields)
many-to-one relationship
19. The database that will be used if this query is executed now
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
annotate(args - *kwargs)
&
db
20. 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.
aggregate(args - *kwargs)
istartswith
exact
Entry.objects.filter(pub_date__range=(start_date - end_date))
21. 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.
Q()
regex
relationship spanning
aggregate(args - *kwargs)
22. This field is added automatically - but this behavior can be overridden
values(*fields)
id field
iregex
get(**kwargs)
23. Returns the most recent object in the table - by date - using the field_name provided as the date field.
model
MultipleObjectsReturned
endswith
latest(field_name=None)
24. 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()
pickling
distinct()
25. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
Restrictions on field names
model
related_name
26. 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.
default
Multi-table inheritance
model
update()
27. A Python "magic method" that returns a unicode "representation" of any object.
istartswith
__unicode__()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
relationship spanning
28. This query finds all entries with an id greater than 4.
order_by(*fields)
Meta class
gte
Entry.objects.filter(id__gt=4)
29. 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
Entry.objects.filter(pub_date__year=2005).delete()
endswith
pickling
30. Conjuntion operator for Q objects.
DoesNotExist
search
~
&
31. Lookup type that returns results with a case-sensitive end sequence.
exclude(**kwargs)
endswith
choices
Manager
32. The default for this is the name of the child class followed by '_set'.
ordered
default
reverse name
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
33. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
iendswith
iexact
gte
Field lookups
34. This is a criterion that narrow down a QuerySet based on given parameters.
null
update(**kwargs)
slicing
filter
35. 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
get_absolute_url()
exists()
pk
when you add new apps to INSTALLED_APPS
36. 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.
help_text
ManyToManyField
F()
Entry.objects.filter(pub_date__range=(start_date - end_date))
37. 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
endswith
id field
class type
__unicode__()
38. Fields are specified by these
class attributes
week_day
annotate(args - *kwargs)
ForeignKey
39. This model method saves a model instance to the database. This method has no return value.
get(**kwargs)
gte
class type
save()
40. 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
Model metadata
update()
only(*fields)
search
41. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
related_name
values(*fields)
gte
help_text
42. Lookup type for date/datetime fields that finds an exact day match.
gt
week_day
Q(question__istartswith='What')
day
43. 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.
one-to-one relationship
search
annotate(args - *kwargs)
MultipleObjectsReturned
44. 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
relationship spanning
update(**kwargs)
annotate(args - *kwargs)
in
45. 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()
update(**kwargs)
evaluation
Manager
Q()
46. 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.
pickling
evaluation
Entry.objects.filter(id__gt=4)
choices tuple
47. 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
defer(*fields)
istartswith
Field lookups
model
48. Lookup type that finds a case-sensitive regular expression match.
regex
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
all()
Many-to-many relationship to self
49. Lookup type that returns results in a given list.
Entry.objects.filter(pub_date__range=(start_date - end_date))
get_absolute_url()
in
gte
50. 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.
Meta class
get(**kwargs)
Model metadata
Multi-table inheritance