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. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
search
filter(**kwargs)
choices tuple
in
2. 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.
in_bulk(id_list)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
defer(*fields)
contains
3. 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
lte
related_name
iterator()
create(**kwargs)
4. 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.
search
id field
using(alias)
class attributes
5. If True - the table does not permit duplicate values for this field.
day
F()
unique
blank
6. Lookup type that tests for inclusion in a case-sensitive fashion.
get_absolute_url()
contains
regex
none()
7. 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.
istartswith
filter chaining
Abstract base class
only(*fields)
8. 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
get_or_create(**kwargs)
annotate(args - *kwargs)
Entry.objects.filter(id__gt=4)
9. Returns the most recent object in the table - by date - using the field_name provided as the date field.
create(**kwargs)
Entry.objects.filter(id__in=[1 - 3 - 4])
update()
latest(field_name=None)
10. Returns a new QuerySet containing objects that match the given lookup parameters.
add()
filter(**kwargs)
Multi-table inheritance
regex
11. These add custom "row-level" functionality to your objects. These act on a particular model instance.
iterator()
QuerySet
exact
Custom model methods
12. 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
Many-to-many relationship to self
none()
select_related()
Meta class
13. a QuerySet can be sliced - using Python's array-slicing syntax.
in
iregex
slicing
choices tuple
14. 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.
OneToOneField
in
only(*fields)
primary_key
15. 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.
count()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
distinct()
Restrictions on field names
16. Fields are specified by these
__unicode__()
class attributes
relationship spanning
only(*fields)
17. This method immediately deletes the object and has no return value.
all()
delete()
|
update()
18. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
evaluation
Many-to-many relationship through an intermediate model
filter(**kwargs)
aggregate(args - *kwargs)
19. If True - this field is the primary key for the model.
pickling
class type
ForeignKey
primary_key
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.
pickling
through argument
Entry.objects.filter(pub_date__range=(start_date - end_date))
Model metadata
21. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
get_or_create(**kwargs)
aggregate(args - *kwargs)
Multi-table inheritance
model
22. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
blank
get(**kwargs)
==
add()
23. 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
update(**kwargs)
Many-to-many relationship to self
class attributes
year
24. 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
25. 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.
intermediate models
aggregate(args - *kwargs)
order_by(*fields)
filter(**kwargs)
26. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
~
delete()
iteration
27. These methods are intended to do "table-wide" things.
one-to-one relationship
Manager methods
contains
iexact
28. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
order_by(*fields)
ManyToManyField
create(**kwargs)
year
29. 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
30. 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
latest(field_name=None)
|
many-to-one relationship
only(*fields)
31. When to run syncdb
when you add new apps to INSTALLED_APPS
filter(**kwargs)
Many-to-many relationship through an intermediate model
lte
32. This gives your model metadata.
regex
__unicode__()
only(*fields)
Meta class
33. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
when you add new apps to INSTALLED_APPS
values(*fields)
filter(**kwargs)
Custom model methods
34. Lookup type that returns results with a case-sensitive end sequence.
unique
gte
endswith
Custom model methods
35. Lookup type that returns results with a case-insensitive start sequence.
in_bulk(id_list)
istartswith
filter chaining
null
36. 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
filter
null
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
37. (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.
Meta class
F()
Restrictions on field names
==
38. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
exact
iterator()
evaluation
39. If this option is True - Django will store empty values as NULL in the database. Default is False.
class attributes
null
Abstract base class
help_text
40. Lookup type that returns results less than a given value.
search
db
lt
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
41. Lookup type that returns results greater than or equal to a given value.
DoesNotExist
Entry.objects.filter(id__gt=4)
gte
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
42. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
through argument
primary_key
Meta class
iteration
43. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
Meta class
count()
DoesNotExist
choices tuple
44. 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)
Model metadata
related_name
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
in_bulk(id_list)
45. To activate your models
exclude(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
filter chaining
filter
46. 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
QuerySet
annotate(args - *kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Entry.objects.filter(id__in=[1 - 3 - 4])
47. Lookup type that returns results that fall into an inclusive date range.
search
range
Custom model methods
clear() method
48. 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.
gte
reverse()
Q()
through argument
49. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
==
many-to-many relationship
default
50. Can be used to remove all many-to-many relationships for an instance
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
filter
Custom model methods
clear() method