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. 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.
isnull
exclude(**kwargs)
many-to-one relationship
search
2. Used to get a QuerySet for a model. This is called 'objects' by default.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
exclude(**kwargs)
Manager
choices
3. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
4. 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
Q()
default
F()
Entry.objects.filter(id__gt=4)
5. A convenience method for constructing an object and saving it all in one step.
Entry.objects.filter(pub_date__year=2005).delete()
create(**kwargs)
count()
many-to-one relationship
6. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Restrictions on field names
MultipleObjectsReturned
Abstract base class
month
7. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
dates(field - kind - order='ASC')
Manager
==
8. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
values_list(*fields)
exclude(**kwargs)
only(*fields)
gte
9. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
lt
Q(question__istartswith='What')
relationship spanning
10. If True - this field is the primary key for the model.
pk
primary_key
MultipleObjectsReturned
Restrictions on field names
11. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
range
__unicode__()
default
12. These methods are intended to do "table-wide" things.
QuerySet
filter chaining
Manager methods
ManyToManyField
13. 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
ForeignKey
in_bulk(id_list)
update()
14. A Python "magic method" that returns a unicode "representation" of any object.
aggregate(args - *kwargs)
__unicode__()
get_absolute_url()
Many-to-many relationship through an intermediate model
15. 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.
filter chaining
Field lookups
update()
year
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.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
17. Lookup type that returns results with a case-insensitive end sequence.
search
istartswith
iendswith
relationship spanning
18. This query finds all entries with an id in the list [1 - 3 - 4]
filter(**kwargs)
slicing
Entry.objects.filter(id__in=[1 - 3 - 4])
QuerySet
19. The database that will be used if this query is executed now
gt
db
get(**kwargs)
get(**kwargs)
20. 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
21. This model method saves a model instance to the database. This method has no return value.
istartswith
save()
get_absolute_url()
model
22. This model method is used for updating a ManyToManyField.
range
many-to-one relationship
add()
default
23. 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.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Many-to-many relationship through an intermediate model
isnull
latest(field_name=None)
24. (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.
Manager
one-to-one relationship
Restrictions on field names
using(alias)
25. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
filter chaining
related_name
pickling
iteration
26. 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
create(**kwargs)
annotate(args - *kwargs)
dates(field - kind - order='ASC')
latest(field_name=None)
27. Returns the object matching the given lookup parameters
week_day
get(**kwargs)
none()
through argument
28. 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.
delete()
year
distinct()
Model metadata
29. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
Model metadata
exists()
filter chaining
30. This field is added automatically - but this behavior can be overridden
Many-to-many relationship through an intermediate model
Proxy model
id field
Manager methods
31. If True - the table does not permit duplicate values for this field.
using(alias)
unique
null
range
32. 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
ordered
defer(*fields)
save()
none()
33. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
class attributes
lt
isnull
34. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
gte
get_or_create(**kwargs)
QuerySet
35. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
Entry.objects.filter(pub_date__range=(start_date - end_date))
update()
Many-to-many relationship to self
36. Lookup type for date/datetime fields that finds an exact day match.
Manager methods
day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
iendswith
37. 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.
add()
get(**kwargs)
iteration
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
38. 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
ForeignKey
exists()
pickling
all()
39. This method immediately deletes the object and has no return value.
day
delete()
help_text
dates(field - kind - order='ASC')
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
in
iendswith
Many-to-many relationship to self
Abstract base class
41. 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.
regex
==
reverse()
help_text
42. 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.
using(alias)
ForeignKey
Q(question__istartswith='What')
iregex
43. Returns a new QuerySet containing objects that match the given lookup parameters.
distinct()
default
unique
filter(**kwargs)
44. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
one-to-one relationship
aggregate(args - *kwargs)
isnull
defer(*fields)
45. Lookup type that finds a case-insensitive regular expression match.
intermediate models
iregex
select_related()
MultipleObjectsReturned
46. 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.
Many-to-many relationship through an intermediate model
ManyToManyField
clear() method
iteration
47. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
select_related()
OneToOneField
values_list(*fields)
model
48. 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.
update(**kwargs)
in_bulk(id_list)
ForeignKey
Abstract base class
49. This query uses an F object to increment the pingback count for every entry in the blog.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
50. 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
exact
iterator()
ManyToManyField
defer(*fields)