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. 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
one-to-one relationship
Entry.objects.filter(id__gt=4)
iteration
2. 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
Multi-table inheritance
intermediate models
select_related()
==
3. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Q()
gte
Entry.objects.filter(pub_date__range=(start_date - end_date))
==
4. 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
through argument
contains
defer(*fields)
QuerySet
5. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
id field
OneToOneField
get(**kwargs)
6. 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.
aggregate(args - *kwargs)
ManyToManyField
help_text
update(**kwargs)
7. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
reverse name
range
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
8. A convenience method for looking up an object with the given kwargs - creating one if necessary.
count()
get_or_create(**kwargs)
iterator()
Multi-table inheritance
9. This query finds all entries between a start date of start_date and an end date of end_date.
update()
order_by(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
10. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
week_day
iendswith
startswith
11. 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.
Q(question__istartswith='What')
add()
relationship spanning
OneToOneField
12. Lookup type that returns results greater than a given value.
all()
delete()
Entry.objects.filter(id__gt=4)
gt
13. 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.
many-to-one relationship
get(**kwargs)
choices
Proxy model
14. If this option is True - the field is allowed to be blank. Default is False.
filter(**kwargs)
model
id field
blank
15. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
Model metadata
default
count()
Many-to-many relationship to self
16. The database that will be used if this query is executed now
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
db
defer(*fields)
endswith
17. This is a criterion that narrow down a QuerySet based on given parameters.
Manager
filter
default
model
18. If this option is True - Django will store empty values as NULL in the database. Default is False.
db
latest(field_name=None)
values(*fields)
null
19. Exception raised by get(**kwargs) if no items match the query.
create(**kwargs)
latest(field_name=None)
annotate(args - *kwargs)
DoesNotExist
20. 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.
MultipleObjectsReturned
search
Entry.objects.filter(id__in=[1 - 3 - 4])
pickling
21. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
none()
db
22. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
delete()
intermediate models
blank
23. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
filter
in
startswith
iteration
24. 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
~
select_related()
none()
annotate(args - *kwargs)
25. 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.
iexact
Many-to-many relationship through an intermediate model
iterator()
choices tuple
26. (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.
Restrictions on field names
dates(field - kind - order='ASC')
ordered
delete()
27. Negation operator for Q objects.
~
when you add new apps to INSTALLED_APPS
one-to-one relationship
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
28. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
dates(field - kind - order='ASC')
through argument
Model metadata
29. 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.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
many-to-one relationship
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
delete()
30. 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.
help_text
latest(field_name=None)
ordered
Field lookups
31. 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.
day
iterator()
all()
filter chaining
32. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
QuerySet
all()
reverse name
33. Lookup type that finds a case-sensitive regular expression match.
get_or_create(**kwargs)
Q()
regex
delete()
34. 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
|
Proxy model
year
iendswith
35. By default - results returned by a QuerySet are ordered by the ordering tuple given by the ordering option in the model's Meta. You can override this on a per-QuerySet basis by using the this method.
get_or_create(**kwargs)
order_by(*fields)
evaluation
primary_key
36. 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()
evaluation
Model metadata
none()
37. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
pickling
all()
model
exclude(**kwargs)
38. a QuerySet can be sliced - using Python's array-slicing syntax.
get_or_create(**kwargs)
==
add()
slicing
39. This field is added automatically - but this behavior can be overridden
Entry.objects.filter(id__gt=4)
id field
null
ForeignKey
40. The default for this is the name of the child class followed by '_set'.
reverse name
delete()
only(*fields)
unique
41. 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.
one-to-one relationship
update()
filter chaining
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
42. These add custom "row-level" functionality to your objects. These act on a particular model instance.
get(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
exact
Custom model methods
43. Conjuntion operator for Q objects.
in
defer(*fields)
Proxy model
&
44. 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)
evaluation
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
db
45. When to run syncdb
gte
Entry.objects.filter(id__in=[1 - 3 - 4])
when you add new apps to INSTALLED_APPS
get_or_create(**kwargs)
46. Lookup type for date/datetime fields that finds an exact day match.
many-to-many relationship
primary_key
day
get_absolute_url()
47. Lookup type that yields a case-insensitive match.
iexact
Entry.objects.filter(id__gt=4)
Many-to-many relationship to self
search
48. 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
49. This represents a collection of objects from your database. It can have zero - one or many filters.
related_name
relationship spanning
MultipleObjectsReturned
QuerySet
50. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
|
many-to-many relationship
contains
Entry.objects.filter(pub_date__year=2005).delete()