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. Lookup type that returns results greater than a given value.
gt
Proxy model
DoesNotExist
add()
2. Fields are specified by these
class attributes
order_by(*fields)
default
MultipleObjectsReturned
3. 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()
iregex
values(*fields)
4. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
QuerySet
add()
delete()
values(*fields)
5. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
==
blank
iterator()
Field lookups
6. Lookup type for date/datetime fields that finds a 'day of the week' match.
ordered
week_day
unique
iterator()
7. (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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Restrictions on field names
class attributes
aggregate(args - *kwargs)
8. Exception raised by get(**kwargs) if more than one item matches the query.
reverse name
gte
MultipleObjectsReturned
endswith
9. 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.
clear() method
get_absolute_url()
&
Model metadata
10. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
delete()
pk
one-to-one relationship
Custom model methods
11. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
pk
ordered
lte
filter
12. A convenience method for looking up an object with the given kwargs - creating one if necessary.
filter
choices
F()
get_or_create(**kwargs)
13. Conjuntion operator for Q objects.
distinct()
lt
using(alias)
&
14. Returns the object matching the given lookup parameters
get(**kwargs)
class type
unique
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
15. 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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
slicing
Restrictions on field names
16. 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.
17. Performs an SQL update query for the specified fields - and returns the number of rows affected. This method is applied instantly and the only restriction on the QuerySet that is updated is that it can only update columns in the model's main table. F
week_day
exists()
update(**kwargs)
add()
18. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
19. Lookup type that returns results less than a given value.
lt
search
endswith
defer(*fields)
20. This model method saves a model instance to the database. This method has no return value.
save()
&
MultipleObjectsReturned
primary_key
21. Lookup type that finds a case-insensitive regular expression match.
exists()
iregex
aggregate(args - *kwargs)
endswith
22. Lookup type that yields a case-insensitive match.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
MultipleObjectsReturned
|
iexact
23. Lookup type that returns results that fall into an inclusive date range.
order_by(*fields)
range
many-to-one relationship
evaluation
24. 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
ordered
reverse()
update()
25. 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)
get_absolute_url()
all()
values(*fields)
26. Disjunction operator for Q objects.
Abstract base class
|
Custom model methods
pickling
27. When to run syncdb
blank
Manager
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
when you add new apps to INSTALLED_APPS
28. a QuerySet can be sliced - using Python's array-slicing syntax.
all()
lte
slicing
startswith
29. 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.
Many-to-many relationship to self
OneToOneField
all()
annotate(args - *kwargs)
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.
iexact
exact
related_name
Entry.objects.filter(id__in=[1 - 3 - 4])
31. 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.
iendswith
reverse()
Manager
DoesNotExist
32. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
OneToOneField
update()
id field
33. 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
create(**kwargs)
through argument
filter(**kwargs)
help_text
34. 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.
Manager
iteration
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
distinct()
35. 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
count()
one-to-one relationship
all()
class type
36. Returns a new QuerySet containing objects that match the given lookup parameters.
dates(field - kind - order='ASC')
count()
filter(**kwargs)
~
37. The database that will be used if this query is executed now
unique
db
range
Restrictions on field names
38. Lookup type that finds a case-sensitive regular expression match.
regex
id field
all()
delete()
39. Lookup type that tests for inclusion in a case-sensitive fashion.
Field lookups
contains
ordered
search
40. 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
Abstract base class
only(*fields)
QuerySet
Field lookups
41. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
many-to-many relationship
isnull
Entry.objects.filter(id__gt=4)
iendswith
42. Lookup type for date/datetime fields that finds an exact day match.
order_by(*fields)
day
relationship spanning
contains
43. 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)
aggregate(args - *kwargs)
unique
endswith
44. Lookup type that returns results in a given list.
in
reverse()
only(*fields)
get_or_create(**kwargs)
45. To activate your models
month
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Many-to-many relationship to self
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
46. This method immediately deletes the object and has no return value.
Field lookups
delete()
lt
iendswith
47. If True - the table does not permit duplicate values for this field.
unique
all()
choices tuple
values_list(*fields)
48. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
all()
lt
class type
49. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
get(**kwargs)
all()
==
Field lookups
50. This query finds all entries with an id in the list [1 - 3 - 4]
relationship spanning
lt
through argument
Entry.objects.filter(id__in=[1 - 3 - 4])