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. 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
2. A convenience method for constructing an object and saving it all in one step.
choices
ManyToManyField
create(**kwargs)
DoesNotExist
3. If True - this field is the primary key for the model.
lt
Entry.objects.filter(pub_date__year=2005).delete()
evaluation
primary_key
4. 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
istartswith
none()
intermediate models
Many-to-many relationship through an intermediate model
5. 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.
lt
help_text
related_name
model
6. Manager method used to retrieve every object in a model.
Entry.objects.filter(id__gt=4)
aggregate(args - *kwargs)
all()
get_absolute_url()
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.
Multi-table inheritance
add()
week_day
select_related()
8. 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
9. 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
values_list(*fields)
Q(question__istartswith='What')
iterator()
10. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
defer(*fields)
choices tuple
distinct()
Manager
11. 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.
Manager methods
intermediate models
in_bulk(id_list)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
12. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Multi-table inheritance
ordered
values_list(*fields)
==
13. 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.
in
ManyToManyField
Many-to-many relationship to self
db
14. Can be used to remove all many-to-many relationships for an instance
filter(**kwargs)
clear() method
related_name
save()
15. Lookup type that finds a case-sensitive regular expression match.
aggregate(args - *kwargs)
regex
none()
Multi-table inheritance
16. This is a criterion that narrow down a QuerySet based on given parameters.
related_name
filter
filter chaining
reverse()
17. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
unique
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Entry.objects.filter(pub_date__range=(start_date - end_date))
18. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
contains
annotate(args - *kwargs)
lte
exclude(**kwargs)
19. 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
choices tuple
dates(field - kind - order='ASC')
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
only(*fields)
20. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
order_by(*fields)
iteration
__unicode__()
choices tuple
21. 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
filter(**kwargs)
relationship spanning
isnull
22. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
OneToOneField
filter chaining
related_name
Entry.objects.filter(id__gt=4)
23. 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
delete()
create(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
24. To activate your models
order_by(*fields)
iexact
default
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
25. 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.
filter chaining
Many-to-many relationship through an intermediate model
Q()
reverse name
26. Lookup type that returns results with a case-sensitive end sequence.
exists()
delete()
iteration
endswith
27. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
lte
only(*fields)
model
choices tuple
28. 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.
istartswith
db
pickling
year
29. Conjuntion operator for Q objects.
&
count()
iexact
lt
30. 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
lt
gt
intermediate models
filter(**kwargs)
31. 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.
all()
aggregate(args - *kwargs)
count()
all()
32. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
only(*fields)
many-to-many relationship
aggregate(args - *kwargs)
iendswith
33. The default for this is the name of the child class followed by '_set'.
only(*fields)
reverse name
gt
Abstract base class
34. Lookup type that returns results that fall into an inclusive date range.
save()
in_bulk(id_list)
range
filter chaining
35. Fields are specified by these
__unicode__()
class attributes
Entry.objects.filter(pub_date__range=(start_date - end_date))
gte
36. A convenience method for looking up an object with the given kwargs - creating one if necessary.
many-to-many relationship
get_absolute_url()
many-to-one relationship
get_or_create(**kwargs)
37. 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.
unique
exact
many-to-many relationship
aggregate(args - *kwargs)
38. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iterator()
values_list(*fields)
evaluation
39. 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
40. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
slicing
year
search
count()
41. 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.
__unicode__()
ForeignKey
all()
search
42. 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
get_absolute_url()
class attributes
clear() method
43. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Field lookups
Q()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
one-to-one relationship
44. 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()
&
MultipleObjectsReturned
evaluation
filter(**kwargs)
45. Lookup type that yields a case-insensitive match.
filter(**kwargs)
iexact
MultipleObjectsReturned
search
46. 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
47. Lookup type that returns results greater than or equal to a given value.
delete()
QuerySet
gte
ManyToManyField
48. Lookup type that returns results with a case-insensitive start sequence.
contains
istartswith
Many-to-many relationship through an intermediate model
Multi-table inheritance
49. Lookup type that finds a case-insensitive regular expression match.
Q()
when you add new apps to INSTALLED_APPS
iregex
ordered
50. 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.
save()
when you add new apps to INSTALLED_APPS
iregex
choices tuple