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. Disjunction operator for Q objects.
contains
search
|
reverse name
2. 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
only(*fields)
Manager
model
3. This model type is useful if you only want to modify the Python-level behavior of a model - without changing the models fields in any way. This creates a stand-in for the original model. You can create - delete and update instances of this new model
annotate(args - *kwargs)
slicing
values_list(*fields)
Proxy model
4. 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.
values_list(*fields)
count()
filter(**kwargs)
update(**kwargs)
5. Lookup type that returns results less than a given value.
choices
annotate(args - *kwargs)
exists()
lt
6. 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
filter chaining
update(**kwargs)
exists()
search
7. Lookup type for date/datetime fields that finds an exact day match.
day
ForeignKey
~
using(alias)
8. 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.
Model metadata
DoesNotExist
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Q()
9. Lookup type that yields a case-insensitive match.
select_related()
model
iexact
filter chaining
10. 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.
filter
using(alias)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
filter(**kwargs)
11. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
filter chaining
default
MultipleObjectsReturned
get_absolute_url()
12. This field is added automatically - but this behavior can be overridden
id field
Proxy model
filter(**kwargs)
Model metadata
13. 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
14. 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.
MultipleObjectsReturned
ForeignKey
exclude(**kwargs)
get(**kwargs)
15. This gives your model metadata.
Meta class
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)
F()
16. 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.
year
when you add new apps to INSTALLED_APPS
ForeignKey
reverse()
17. Lookup type that returns results greater than or equal to a given value.
gte
Abstract base class
select_related()
slicing
18. Lookup type that finds a case-insensitive regular expression match.
Many-to-many relationship through an intermediate model
db
startswith
iregex
19. 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
aggregate(args - *kwargs)
search
all()
in
20. (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.
filter(**kwargs)
Restrictions on field names
Proxy model
Model metadata
21. 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
22. 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)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
update(**kwargs)
many-to-many relationship
Model metadata
23. Lookup type that tests for inclusion in a case-sensitive fashion.
many-to-many relationship
contains
Entry.objects.filter(id__in=[1 - 3 - 4])
model
24. a QuerySet can be sliced - using Python's array-slicing syntax.
iterator()
id field
Entry.objects.filter(id__in=[1 - 3 - 4])
slicing
25. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
26. 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
reverse()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
update()
27. This query finds all entries between a start date of start_date and an end date of end_date.
many-to-one relationship
range
Entry.objects.filter(pub_date__range=(start_date - end_date))
defer(*fields)
28. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
filter(**kwargs)
unique
month
help_text
29. 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
Custom model methods
id field
ordered
iterator()
30. 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.
iteration
iregex
Abstract base class
OneToOneField
31. 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()
iexact
distinct()
month
32. These methods are intended to do "table-wide" things.
Manager methods
Manager
delete()
ForeignKey
33. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
create(**kwargs)
exclude(**kwargs)
iexact
delete()
34. 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
exclude(**kwargs)
gt
choices tuple
35. Negation operator for Q objects.
Q(question__istartswith='What')
~
choices tuple
F()
36. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.
Many-to-many relationship to self
class attributes
order_by(*fields)
help_text
37. A convenience method for constructing an object and saving it all in one step.
|
&
create(**kwargs)
filter(**kwargs)
38. 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.
week_day
all()
choices
endswith
39. 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
order_by(*fields)
none()
class type
db
40. Used to get a QuerySet for a model. This is called 'objects' by default.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
isnull
istartswith
Manager
41. The database that will be used if this query is executed now
range
db
Meta class
clear() method
42. If True - this field is the primary key for the model.
Q(question__istartswith='What')
create(**kwargs)
primary_key
through argument
43. This model method is used for updating a ManyToManyField.
add()
regex
order_by(*fields)
update(**kwargs)
44. This method immediately deletes the object and has no return value.
order_by(*fields)
delete()
Multi-table inheritance
DoesNotExist
45. If this option is True - the field is allowed to be blank. Default is False.
blank
Manager methods
iexact
filter chaining
46. Lookup type that returns results in a given list.
Entry.objects.filter(pub_date__range=(start_date - end_date))
in
many-to-one relationship
ForeignKey
47. This query deletes all Entry objects with a pub_date year of 2005.
gt
Entry.objects.filter(pub_date__year=2005).delete()
Q()
DoesNotExist
48. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
OneToOneField
count()
year
reverse()
49. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
F()
Entry.objects.filter(id__in=[1 - 3 - 4])
order_by(*fields)
50. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
relationship spanning
help_text
OneToOneField
istartswith