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 convenience method for constructing an object and saving it all in one step.
create(**kwargs)
year
week_day
update()
2. This gives your model metadata.
DoesNotExist
many-to-one relationship
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Meta class
3. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
ordered
defer(*fields)
regex
4. 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.
Q()
all()
Abstract base class
in_bulk(id_list)
5. This model method saves a model instance to the database. This method has no return value.
MultipleObjectsReturned
save()
lt
week_day
6. A Python "magic method" that returns a unicode "representation" of any object.
get(**kwargs)
order_by(*fields)
Restrictions on field names
__unicode__()
7. Manager method used to retrieve every object in a model.
all()
add()
startswith
gte
8. These methods are intended to do "table-wide" things.
regex
Proxy model
Field lookups
Manager methods
9. This query finds all entries with an id in the list [1 - 3 - 4]
day
through argument
relationship spanning
Entry.objects.filter(id__in=[1 - 3 - 4])
10. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
intermediate models
MultipleObjectsReturned
add()
11. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
12. 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
all()
defer(*fields)
filter(**kwargs)
==
13. The default for this is the name of the child class followed by '_set'.
all()
update(**kwargs)
reverse name
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
14. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
OneToOneField
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
month
many-to-many relationship
15. 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
select_related()
contains
iregex
lt
16. 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.
update(**kwargs)
related_name
order_by(*fields)
Entry.objects.filter(id__gt=4)
17. 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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
~
get_or_create(**kwargs)
18. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values(*fields)
filter(**kwargs)
ordered
19. Lookup type that returns results greater than a given value.
distinct()
gt
range
isnull
20. Lookup type that tests for inclusion in a case-sensitive fashion.
save()
many-to-one relationship
contains
Restrictions on field names
21. 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
search
none()
update(**kwargs)
|
22. 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
annotate(args - *kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iregex
23. 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
default
null
through argument
Custom model methods
24. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
isnull
id field
==
year
25. 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
Proxy model
Model metadata
slicing
26. Can be used to remove all many-to-many relationships for an instance
clear() method
|
id field
Manager methods
27. Used to get a QuerySet for a model. This is called 'objects' by default.
year
Q()
Manager
aggregate(args - *kwargs)
28. Lookup type that returns results with a case-sensitive start sequence.
values(*fields)
startswith
iendswith
Many-to-many relationship through an intermediate model
29. (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.
when you add new apps to INSTALLED_APPS
Restrictions on field names
pk
get(**kwargs)
30. Lookup type that finds a case-insensitive regular expression match.
year
iregex
lt
filter(**kwargs)
31. 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.
latest(field_name=None)
delete()
reverse name
values(*fields)
32. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
month
model
year
33. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
iexact
isnull
create(**kwargs)
istartswith
34. If True - this field is the primary key for the model.
filter(**kwargs)
aggregate(args - *kwargs)
QuerySet
primary_key
35. Lookup type that returns results less than a given value.
lt
class type
values(*fields)
month
36. If True - the table does not permit duplicate values for this field.
evaluation
unique
reverse name
Custom model methods
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
Model metadata
Custom model methods
Abstract base class
isnull
38. 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.
QuerySet
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)
values(*fields)
39. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)
evaluation
Model metadata
reverse name
filter(**kwargs)
40. Fields are specified by these
null
&
class attributes
iexact
41. 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
Proxy model
values_list(*fields)
iterator()
day
42. Lookup type that returns results in a given list.
exact
in
Custom model methods
ordered
43. 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.
delete()
OneToOneField
get(**kwargs)
unique
44. This method immediately deletes the object and has no return value.
filter
one-to-one relationship
Q()
delete()
45. 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.
exists()
get_absolute_url()
when you add new apps to INSTALLED_APPS
==
46. Lookup type that finds a case-sensitive regular expression match.
aggregate(args - *kwargs)
gte
regex
iteration
47. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
db
pk
search
48. This query finds all entries with an id greater than 4.
iexact
Q(question__istartswith='What')
Entry.objects.filter(id__gt=4)
istartswith
49. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
class type
&
DoesNotExist
50. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
select_related()
filter chaining
ForeignKey