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. 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
2. Lookup type that yields an "exact" match. If you don't provide a lookup type -- that is - if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be of this sort.
Restrictions on field names
get(**kwargs)
exact
gt
3. Lookup type that returns results greater than a given value.
intermediate models
gt
related_name
all()
4. Lookup type that returns results that fall into an inclusive date range.
range
gt
using(alias)
~
5. 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
distinct()
__unicode__()
DoesNotExist
6. Used to get a QuerySet for a model. This is called 'objects' by default.
ManyToManyField
==
Q()
Manager
7. 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.
default
Many-to-many relationship to self
Multi-table inheritance
save()
8. Returns the object matching the given lookup parameters
Proxy model
filter
get(**kwargs)
through argument
9. 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.
relationship spanning
using(alias)
filter(**kwargs)
Many-to-many relationship through an intermediate model
10. If this option is True - Django will store empty values as NULL in the database. Default is False.
latest(field_name=None)
select_related()
many-to-many relationship
null
11. Returns a new QuerySet containing objects that match the given lookup parameters.
delete()
filter(**kwargs)
exists()
class type
12. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
intermediate models
one-to-one relationship
select_related()
iregex
13. A convenience method for constructing an object and saving it all in one step.
model
reverse()
create(**kwargs)
Many-to-many relationship through an intermediate model
14. 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
select_related()
DoesNotExist
only(*fields)
values_list(*fields)
15. 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
db
relationship spanning
distinct()
blank
16. To activate your models
MultipleObjectsReturned
ForeignKey
OneToOneField
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
17. Manager method used to retrieve every object in a model.
Entry.objects.filter(pub_date__range=(start_date - end_date))
all()
slicing
unique
18. 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
iterator()
QuerySet
filter(**kwargs)
blank
19. 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.
Many-to-many relationship through an intermediate model
evaluation
when you add new apps to INSTALLED_APPS
choices tuple
20. Disjunction operator for Q objects.
lte
choices
|
select_related()
21. 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
select_related()
DoesNotExist
latest(field_name=None)
22. Exception raised by get(**kwargs) if no items match the query.
startswith
DoesNotExist
__unicode__()
Manager methods
23. If True - the table does not permit duplicate values for this field.
many-to-many relationship
search
unique
defer(*fields)
24. Lookup type that returns results greater than or equal to a given value.
exclude(**kwargs)
ForeignKey
Manager methods
gte
25. 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
exists()
filter(**kwargs)
aggregate(args - *kwargs)
id field
26. Lookup type that returns results with a case-sensitive end sequence.
filter chaining
endswith
exclude(**kwargs)
get(**kwargs)
27. This query finds all entries with an id in the list [1 - 3 - 4]
delete()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Many-to-many relationship through an intermediate model
Entry.objects.filter(id__in=[1 - 3 - 4])
28. These methods are intended to do "table-wide" things.
id field
Manager methods
exclude(**kwargs)
get(**kwargs)
29. (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.
range
Restrictions on field names
model
QuerySet
30. If True - this field is the primary key for the model.
startswith
primary_key
many-to-many relationship
delete()
31. Lookup type for date/datetime fields that finds an exact day match.
Restrictions on field names
day
iregex
save()
32. 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.
Q(question__istartswith='What')
many-to-one relationship
iterator()
Abstract base class
33. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
many-to-many relationship
filter
|
34. This gives your model metadata.
exact
defer(*fields)
QuerySet
Meta class
35. 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)
endswith
OneToOneField
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.
ManyToManyField
only(*fields)
distinct()
Q()
37. Lookup type for date/datetime fields that finds a 'day of the week' match.
add()
update(**kwargs)
|
week_day
38. The database that will be used if this query is executed now
db
annotate(args - *kwargs)
in_bulk(id_list)
blank
39. 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.
get_or_create(**kwargs)
QuerySet
count()
OneToOneField
40. A convenience method for looking up an object with the given kwargs - creating one if necessary.
search
only(*fields)
get_or_create(**kwargs)
many-to-one relationship
41. Lookup type that yields a case-insensitive match.
iexact
&
distinct()
gte
42. 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.
intermediate models
ManyToManyField
iendswith
class attributes
43. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
create(**kwargs)
filter chaining
using(alias)
year
44. Lookup type that finds a case-sensitive regular expression match.
Model metadata
regex
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(pub_date__year=2005).delete()
45. a QuerySet can be sliced - using Python's array-slicing syntax.
Q()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
slicing
create(**kwargs)
46. This field is added automatically - but this behavior can be overridden
Proxy model
id field
Entry.objects.filter(id__gt=4)
many-to-one relationship
47. This model method saves a model instance to the database. This method has no return value.
count()
id field
when you add new apps to INSTALLED_APPS
save()
48. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
model
distinct()
isnull
id field
49. 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.
through argument
null
range
in_bulk(id_list)
50. Can be used to remove all many-to-many relationships for an instance
iterator()
clear() method
get(**kwargs)
get(**kwargs)