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 returns results in a given list.
in
OneToOneField
values_list(*fields)
exists()
2. 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.
ForeignKey
unique
defer(*fields)
Model metadata
3. Conjuntion operator for Q objects.
filter(**kwargs)
&
class type
OneToOneField
4. Disjunction operator for Q objects.
Entry.objects.filter(id__gt=4)
|
Entry.objects.filter(pub_date__range=(start_date - end_date))
get(**kwargs)
5. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Abstract base class
filter(**kwargs)
many-to-one relationship
Entry.objects.filter(id__in=[1 - 3 - 4])
6. 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
7. 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.
one-to-one relationship
in_bulk(id_list)
distinct()
regex
8. 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
save()
clear() method
select_related()
exact
9. Lookup type that returns results with a case-sensitive start sequence.
none()
startswith
isnull
Manager methods
10. Lookup type for date/datetime fields that finds an exact day match.
defer(*fields)
intermediate models
day
null
11. 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.
Custom model methods
help_text
OneToOneField
latest(field_name=None)
12. 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
13. 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.
values(*fields)
create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
distinct()
14. Lookup type that yields a case-insensitive match.
iexact
model
iregex
get_or_create(**kwargs)
15. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
when you add new apps to INSTALLED_APPS
evaluation
dates(field - kind - order='ASC')
16. Lookup type that returns results greater than a given value.
in_bulk(id_list)
gt
annotate(args - *kwargs)
__unicode__()
17. Lookup type that finds a case-insensitive regular expression match.
F()
year
iregex
latest(field_name=None)
18. When to run syncdb
contains
when you add new apps to INSTALLED_APPS
none()
intermediate models
19. Returns the object matching the given lookup parameters
get(**kwargs)
lt
annotate(args - *kwargs)
Many-to-many relationship through an intermediate model
20. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
one-to-one relationship
many-to-many relationship
contains
Field lookups
21. Negation operator for Q objects.
Custom model methods
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
~
all()
22. 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
class type
only(*fields)
exists()
23. Fields are specified by these
get_or_create(**kwargs)
lt
class type
class attributes
24. 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.
id field
clear() method
filter
get(**kwargs)
25. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
gt
select_related()
filter
26. To activate your models
update()
endswith
intermediate models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
27. (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.
defer(*fields)
Abstract base class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Restrictions on field names
28. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
values(*fields)
reverse name
only(*fields)
29. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
annotate(args - *kwargs)
intermediate models
related_name
ManyToManyField
30. Lookup type for date/datetime fields that finds a 'day of the week' match.
endswith
week_day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
year
31. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
default
when you add new apps to INSTALLED_APPS
lte
32. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
annotate(args - *kwargs)
distinct()
model
class attributes
33. 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)
iregex
add()
34. Can be used to remove all many-to-many relationships for an instance
clear() method
ForeignKey
Many-to-many relationship to self
save()
35. This model method is used for updating a ManyToManyField.
filter
add()
create(**kwargs)
month
36. a QuerySet can be sliced - using Python's array-slicing syntax.
ordered
slicing
Entry.objects.filter(id__gt=4)
MultipleObjectsReturned
37. 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.
filter chaining
in
annotate(args - *kwargs)
get_absolute_url()
38. 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)
unique
default
related_name
39. 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.
reverse name
pickling
values_list(*fields)
range
40. This field is added automatically - but this behavior can be overridden
id field
Model metadata
search
in
41. 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
default
reverse name
exact
none()
42. 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()
Proxy model
evaluation
|
__unicode__()
43. 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.
reverse()
ordered
reverse name
in_bulk(id_list)
44. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
in
pk
month
45. The database that will be used if this query is executed now
Custom model methods
db
class type
count()
46. This query finds all entries with an id in the list [1 - 3 - 4]
startswith
Entry.objects.filter(id__in=[1 - 3 - 4])
many-to-one relationship
all()
47. Lookup type that returns results greater than or equal to a given value.
update()
gte
search
slicing
48. 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
get(**kwargs)
evaluation
reverse name
all()
49. This is a criterion that narrow down a QuerySet based on given parameters.
filter
all()
select_related()
get(**kwargs)
50. 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
Manager
defer(*fields)
default
gt