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. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
endswith
dates(field - kind - order='ASC')
delete()
iteration
2. This query finds all entries with an id greater than 4.
ForeignKey
iregex
get(**kwargs)
Entry.objects.filter(id__gt=4)
3. 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.
values_list(*fields)
choices tuple
Abstract base class
using(alias)
4. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
relationship spanning
exact
in
5. The database that will be used if this query is executed now
istartswith
Entry.objects.filter(id__in=[1 - 3 - 4])
db
class type
6. If this option is True - Django will store empty values as NULL in the database. Default is False.
primary_key
Many-to-many relationship through an intermediate model
null
all()
7. 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.
values(*fields)
choices
model
Entry.objects.filter(pub_date__range=(start_date - end_date))
8. Lookup type that returns results that fall into an inclusive date range.
Custom model methods
pk
range
aggregate(args - *kwargs)
9. Lookup type that returns results less than a given value.
get(**kwargs)
week_day
lt
select_related()
10. Fields are specified by these
Proxy model
aggregate(args - *kwargs)
search
class attributes
11. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
12. 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.
using(alias)
null
get(**kwargs)
OneToOneField
13. Lookup type that returns results with a case-sensitive end sequence.
endswith
filter
regex
select_related()
14. Lookup type that finds a case-insensitive regular expression match.
class attributes
month
iregex
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
15. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
month
DoesNotExist
Manager
filter(**kwargs)
16. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
in
count()
OneToOneField
when you add new apps to INSTALLED_APPS
17. Lookup type that finds a case-sensitive regular expression match.
iexact
model
help_text
regex
18. Returns the most recent object in the table - by date - using the field_name provided as the date field.
Restrictions on field names
many-to-one relationship
endswith
latest(field_name=None)
19. Negation operator for Q objects.
~
slicing
isnull
Q()
20. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Abstract base class
pickling
count()
21. 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
Q()
iexact
through argument
delete()
22. These methods are intended to do "table-wide" things.
filter(**kwargs)
Manager methods
DoesNotExist
filter(**kwargs)
23. 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
Meta class
ordered
filter(**kwargs)
relationship spanning
24. The default for this is the name of the child class followed by '_set'.
OneToOneField
startswith
reverse name
year
25. Exception raised by get(**kwargs) if more than one item matches the query.
evaluation
when you add new apps to INSTALLED_APPS
filter(**kwargs)
MultipleObjectsReturned
26. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
many-to-one relationship
null
exists()
related_name
27. 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
Many-to-many relationship through an intermediate model
db
dates(field - kind - order='ASC')
28. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
Manager methods
get(**kwargs)
choices
29. 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
isnull
iendswith
only(*fields)
Abstract base class
30. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
values(*fields)
update(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
31. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
all()
all()
count()
32. If True - this field is the primary key for the model.
clear() method
gte
relationship spanning
primary_key
33. Lookup type that tests for inclusion in a case-sensitive fashion.
day
primary_key
intermediate models
contains
34. Lookup type that returns results with a case-insensitive start sequence.
Field lookups
Q()
Abstract base class
istartswith
35. 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.
save()
using(alias)
==
ForeignKey
36. This method immediately deletes the object and has no return value.
clear() method
delete()
Manager methods
isnull
37. 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
count()
class type
get(**kwargs)
Abstract base class
38. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
istartswith
in_bulk(id_list)
Q()
none()
39. If this option is True - the field is allowed to be blank. Default is False.
blank
~
create(**kwargs)
contains
40. 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
gt
reverse()
exists()
exact
41. 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.
exists()
delete()
evaluation
Proxy model
42. Lookup type that returns results in a given list.
through argument
latest(field_name=None)
distinct()
in
43. 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.
values_list(*fields)
Manager
update()
exclude(**kwargs)
44. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
clear() method
reverse()
F()
distinct()
45. This model method saves a model instance to the database. This method has no return value.
delete()
reverse name
startswith
save()
46. 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.
model
Q()
Restrictions on field names
reverse()
47. This gives your model metadata.
__unicode__()
get_absolute_url()
gte
Meta class
48. 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
Proxy model
range
Many-to-many relationship to self
defer(*fields)
49. (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.
distinct()
Restrictions on field names
exclude(**kwargs)
search
50. a QuerySet can be sliced - using Python's array-slicing syntax.
Manager
many-to-one relationship
evaluation
slicing