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. This query deletes all Entry objects with a pub_date year of 2005.
MultipleObjectsReturned
ManyToManyField
db
Entry.objects.filter(pub_date__year=2005).delete()
2. 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.
Manager
update()
~
get_absolute_url()
3. These add custom "row-level" functionality to your objects. These act on a particular model instance.
gte
Entry.objects.filter(id__in=[1 - 3 - 4])
order_by(*fields)
Custom model methods
4. 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
aggregate(args - *kwargs)
defer(*fields)
filter chaining
annotate(args - *kwargs)
5. 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
many-to-one relationship
gt
iendswith
6. Lookup type that returns results that fall into an inclusive date range.
many-to-one relationship
range
ordered
dates(field - kind - order='ASC')
7. Can be used to remove all many-to-many relationships for an instance
Restrictions on field names
clear() method
Many-to-many relationship to self
ordered
8. This field is added automatically - but this behavior can be overridden
related_name
get(**kwargs)
Proxy model
id field
9. If this option is True - the field is allowed to be blank. Default is False.
iregex
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
in
blank
10. 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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exact
aggregate(args - *kwargs)
clear() method
11. 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.
primary_key
filter
count()
Q()
12. Lookup type that returns results with a case-sensitive end sequence.
class attributes
Meta class
help_text
endswith
13. Lookup type that returns results with a case-insensitive end sequence.
endswith
Many-to-many relationship to self
day
iendswith
14. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Entry.objects.filter(pub_date__year=2005).delete()
help_text
get_or_create(**kwargs)
none()
15. These methods are intended to do "table-wide" things.
istartswith
related_name
Manager methods
Field lookups
16. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
pk
Entry.objects.filter(id__gt=4)
iendswith
17. 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()
in
unique
order_by(*fields)
evaluation
18. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
delete()
gt
Many-to-many relationship through an intermediate model
OneToOneField
19. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
20. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
select_related()
iregex
startswith
distinct()
21. 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.
null
unique
ForeignKey
month
22. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Multi-table inheritance
in_bulk(id_list)
filter chaining
23. 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.
pickling
slicing
iexact
many-to-one relationship
24. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
primary_key
annotate(args - *kwargs)
values_list(*fields)
25. To activate your models
Restrictions on field names
all()
choices tuple
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
26. This gives your model metadata.
aggregate(args - *kwargs)
Meta class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
one-to-one relationship
27. This query finds all entries with an id greater than 4.
|
exists()
Entry.objects.filter(id__gt=4)
startswith
28. Disjunction operator for Q objects.
Custom model methods
Meta class
|
MultipleObjectsReturned
29. 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.
model
choices tuple
none()
choices
30. 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
Entry.objects.filter(id__gt=4)
evaluation
none()
choices
31. (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.
intermediate models
delete()
Restrictions on field names
Entry.objects.filter(pub_date__year=2005).delete()
32. This model method saves a model instance to the database. This method has no return value.
Many-to-many relationship to self
choices
save()
Multi-table inheritance
33. Lookup type that returns results with a case-sensitive start sequence.
filter(**kwargs)
startswith
Field lookups
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
34. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
|
aggregate(args - *kwargs)
MultipleObjectsReturned
35. 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.
ManyToManyField
reverse()
gte
filter(**kwargs)
36. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
all()
reverse name
endswith
using(alias)
37. This is a criterion that narrow down a QuerySet based on given parameters.
iendswith
filter
primary_key
iteration
38. 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
reverse name
in_bulk(id_list)
update(**kwargs)
39. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
clear() method
get_or_create(**kwargs)
db
40. If True - this field is the primary key for the model.
primary_key
Many-to-many relationship through an intermediate model
exclude(**kwargs)
filter
41. 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.
ordered
Q(question__istartswith='What')
exact
reverse()
42. Keyword shortcut for looking up an object by primary key.
get(**kwargs)
get(**kwargs)
pk
all()
43. 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)
Many-to-many relationship through an intermediate model
week_day
Model metadata
day
44. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
all()
id field
exists()
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
class type
ordered
Multi-table inheritance
through argument
46. 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.
Restrictions on field names
order_by(*fields)
range
values_list(*fields)
47. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Manager methods
through argument
many-to-many relationship
istartswith
48. 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.
using(alias)
clear() method
reverse()
delete()
49. 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
iendswith
|
update(**kwargs)
primary_key
50. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
week_day
__unicode__()
select_related()