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. Can be used to remove all many-to-many relationships for an instance
through argument
save()
clear() method
filter
2. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire
iterator()
Multi-table inheritance
Entry.objects.filter(pub_date__year=2005).delete()
null
3. If you pickle a QuerySet - this will force all the results to be loaded into memory prior to pickling. When you unpickle a QuerySet - it contains the results at the moment it was pickled - rather than the results that are currently in the database.
gte
in
pickling
select_related()
4. 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.
in_bulk(id_list)
values(*fields)
save()
choices tuple
5. 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
add()
annotate(args - *kwargs)
in
6. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
evaluation
OneToOneField
model
dates(field - kind - order='ASC')
7. 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
only(*fields)
evaluation
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
delete()
8. Manager method used to retrieve every object in a model.
annotate(args - *kwargs)
Field lookups
all()
Multi-table inheritance
9. Returns the most recent object in the table - by date - using the field_name provided as the date field.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
latest(field_name=None)
Manager
many-to-many relationship
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
Multi-table inheritance
create(**kwargs)
month
11. The default for this is the name of the child class followed by '_set'.
clear() method
day
range
reverse name
12. Returns the object matching the given lookup parameters
|
class type
get(**kwargs)
iterator()
13. If True - this field is the primary key for the model.
help_text
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
primary_key
ordered
14. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
MultipleObjectsReturned
pickling
ManyToManyField
15. Lookup type that returns results less than or equal to a given value.
pickling
lte
add()
Manager methods
16. This model method saves a model instance to the database. This method has no return value.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Q()
save()
using(alias)
17. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
many-to-one relationship
week_day
18. Fields are specified by these
|
annotate(args - *kwargs)
ordered
class attributes
19. Exception raised by get(**kwargs) if no items match the query.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get_or_create(**kwargs)
DoesNotExist
Entry.objects.filter(pub_date__range=(start_date - end_date))
20. 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
using(alias)
get(**kwargs)
QuerySet
through argument
21. 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
class attributes
distinct()
order_by(*fields)
22. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Meta class
one-to-one relationship
model
exclude(**kwargs)
23. These methods are intended to do "table-wide" things.
istartswith
day
Many-to-many relationship through an intermediate model
Manager methods
24. A convenience method for looking up an object with the given kwargs - creating one if necessary.
class attributes
create(**kwargs)
get_or_create(**kwargs)
~
25. 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)
QuerySet
iregex
Custom model methods
26. This field is added automatically - but this behavior can be overridden
~
Entry.objects.filter(pub_date__year=2005).delete()
Manager methods
id field
27. This is a criterion that narrow down a QuerySet based on given parameters.
iexact
filter
Restrictions on field names
~
28. This gives your model metadata.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iregex
Meta class
startswith
29. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
in
exclude(**kwargs)
month
update()
30. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
primary_key
filter
exact
31. Lookup type that finds a case-sensitive regular expression match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
regex
iexact
select_related()
32. 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.
exclude(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
update()
Q()
33. This represents a collection of objects from your database. It can have zero - one or many filters.
all()
Entry.objects.filter(id__gt=4)
Manager methods
QuerySet
34. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
related_name
filter chaining
defer(*fields)
35. A Python "magic method" that returns a unicode "representation" of any object.
Field lookups
__unicode__()
count()
default
36. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
ForeignKey
endswith
Entry.objects.filter(pub_date__year=2005).delete()
37. 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
many-to-many relationship
choices
none()
through argument
38. 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.
many-to-one relationship
Entry.objects.filter(id__gt=4)
select_related()
DoesNotExist
39. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
lte
ordered
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exclude(**kwargs)
40. Lookup type that returns results with a case-insensitive end sequence.
many-to-one relationship
endswith
iendswith
lte
41. 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
__unicode__()
Entry.objects.filter(pub_date__range=(start_date - end_date))
==
42. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
pk
create(**kwargs)
get_absolute_url()
43. Lookup type that returns results greater than a given value.
range
gt
get(**kwargs)
iexact
44. Lookup type for date/datetime fields that finds a 'day of the week' match.
DoesNotExist
delete()
week_day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
45. If True - the table does not permit duplicate values for this field.
reverse name
unique
help_text
class attributes
46. Keyword shortcut for looking up an object by primary key.
latest(field_name=None)
Entry.objects.filter(id__in=[1 - 3 - 4])
in
pk
47. This model method is used for updating a ManyToManyField.
iexact
regex
add()
evaluation
48. This query finds all entries between a start date of start_date and an end date of end_date.
defer(*fields)
in
get_absolute_url()
Entry.objects.filter(pub_date__range=(start_date - end_date))
49. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Many-to-many relationship through an intermediate model
Many-to-many relationship to self
50. Conjuntion operator for Q objects.
&
__unicode__()
day
ForeignKey