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. 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
reverse()
defer(*fields)
2. 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.
delete()
update()
filter
reverse()
3. Lookup type that returns results with a case-insensitive start sequence.
aggregate(args - *kwargs)
Custom model methods
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
istartswith
4. 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
ManyToManyField
OneToOneField
only(*fields)
save()
5. If this option is True - the field is allowed to be blank. Default is False.
all()
==
save()
blank
6. This gives your model metadata.
model
count()
slicing
Meta class
7. Lookup type that returns results greater than a given value.
Manager
create(**kwargs)
week_day
gt
8. A Python "magic method" that returns a unicode "representation" of any object.
==
blank
__unicode__()
get_or_create(**kwargs)
9. 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.
ordered
search
reverse name
__unicode__()
10. Returns an EmptyQuerySet -- a QuerySet that always evaluates to an empty list. This can be used in cases where you know that you should return an empty result set and your caller is expecting a QuerySet object (instead of returning an empty list - fo
Q()
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
none()
11. 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
get(**kwargs)
save()
default
12. Lookup type that returns results that fall into an inclusive date range.
exists()
many-to-one relationship
id field
range
13. Manager method used to retrieve every object in a model.
intermediate models
all()
blank
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
14. 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.
exact
Entry.objects.filter(pub_date__year=2005).delete()
regex
Entry.objects.filter(pub_date__range=(start_date - end_date))
15. This method is for controlling which database the QuerySet will be evaluated against if you are using more than one database. The only argument this method takes is the alias of a database - as defined in DATABASES.
using(alias)
isnull
F()
create(**kwargs)
16. To activate your models
related_name
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
slicing
day
17. 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.
ordered
range
iterator()
filter chaining
18. 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.
Multi-table inheritance
pk
dates(field - kind - order='ASC')
get(**kwargs)
19. If this option is True - Django will store empty values as NULL in the database. Default is False.
Proxy model
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in
null
20. 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.
lte
primary_key
ManyToManyField
in
21. Lookup type that returns results with a case-sensitive start sequence.
startswith
Meta class
lt
clear() method
22. Lookup type that finds a case-insensitive regular expression match.
iregex
values_list(*fields)
latest(field_name=None)
choices tuple
23. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Restrictions on field names
endswith
distinct()
exists()
24. 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))
lt
in_bulk(id_list)
evaluation
25. A convenience method for constructing an object and saving it all in one step.
update(**kwargs)
Entry.objects.filter(id__gt=4)
filter(**kwargs)
create(**kwargs)
26. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.filter(id__in=[1 - 3 - 4])
one-to-one relationship
reverse name
ordered
27. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
28. 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
add()
Entry.objects.filter(id__gt=4)
select_related()
OneToOneField
29. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
default
==
get_or_create(**kwargs)
filter
30. This field is added automatically - but this behavior can be overridden
db
id field
&
iexact
31. Lookup type that returns results less than a given value.
lt
model
startswith
ForeignKey
32. 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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Q()
annotate(args - *kwargs)
help_text
33. Fields are specified by these
&
Many-to-many relationship to self
class attributes
Model metadata
34. Negation operator for Q objects.
all()
~
search
choices tuple
35. Exception raised by get(**kwargs) if more than one item matches the query.
endswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Many-to-many relationship to self
MultipleObjectsReturned
36. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
Manager
MultipleObjectsReturned
iteration
lte
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.
exists()
iterator()
filter chaining
many-to-one relationship
38. Used to get a QuerySet for a model. This is called 'objects' by default.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Manager
get(**kwargs)
values_list(*fields)
39. 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.
update()
through argument
using(alias)
class type
40. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
delete()
model
reverse()
isnull
41. The default for this is the name of the child class followed by '_set'.
reverse name
Q(question__istartswith='What')
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
intermediate models
42. Lookup type that yields a case-insensitive match.
get(**kwargs)
iexact
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
primary_key
43. This model method saves a model instance to the database. This method has no return value.
many-to-many relationship
filter chaining
save()
slicing
44. Lookup type for date/datetime fields that finds a 'day of the week' match.
default
week_day
lte
Field lookups
45. 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
==
iregex
class attributes
through argument
46. Lookup type for date/datetime fields that finds an exact day match.
day
iendswith
order_by(*fields)
create(**kwargs)
47. 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
Entry.objects.filter(id__in=[1 - 3 - 4])
pk
relationship spanning
iterator()
48. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
choices
F()
Field lookups
in
49. 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()
iexact
Entry.objects.filter(id__gt=4)
evaluation
gte
50. 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
Custom model methods
slicing
endswith