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. 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
select_related()
Model metadata
==
Many-to-many relationship to self
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
Proxy model
Many-to-many relationship through an intermediate model
intermediate models
3. Lookup type that returns results greater than or equal to a given value.
db
gte
delete()
iexact
4. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
add()
save()
search
values(*fields)
5. This is a criterion that narrow down a QuerySet based on given parameters.
filter(**kwargs)
filter
blank
class attributes
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. Exception raised by get(**kwargs) if no items match the query.
values_list(*fields)
delete()
slicing
DoesNotExist
8. Lookup type that returns results greater than a given value.
gt
Custom model methods
range
primary_key
9. 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.
class attributes
latest(field_name=None)
OneToOneField
iregex
10. This query finds all entries between a start date of start_date and an end date of end_date.
distinct()
reverse name
QuerySet
Entry.objects.filter(pub_date__range=(start_date - end_date))
11. 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()
model
Entry.objects.filter(pub_date__year=2005).delete()
unique
12. Lookup type that tests for inclusion in a case-sensitive fashion.
Entry.objects.filter(id__gt=4)
filter(**kwargs)
gte
contains
13. 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
Field lookups
Restrictions on field names
through argument
reverse()
14. 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.
one-to-one relationship
pickling
exclude(**kwargs)
filter
15. 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
16. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
default
filter(**kwargs)
get_or_create(**kwargs)
17. Can be used to remove all many-to-many relationships for an instance
Many-to-many relationship through an intermediate model
Manager methods
many-to-many relationship
clear() method
18. This query finds all entries with an id in the list [1 - 3 - 4]
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
one-to-one relationship
Manager
Entry.objects.filter(id__in=[1 - 3 - 4])
19. The database that will be used if this query is executed now
db
save()
filter(**kwargs)
when you add new apps to INSTALLED_APPS
20. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
year
week_day
intermediate models
21. 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
create(**kwargs)
get_or_create(**kwargs)
get(**kwargs)
22. 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.
get_absolute_url()
select_related()
QuerySet
regex
23. This model method is used for updating a ManyToManyField.
defer(*fields)
id field
add()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
24. 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
Multi-table inheritance
order_by(*fields)
in
defer(*fields)
25. 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.
exclude(**kwargs)
&
dates(field - kind - order='ASC')
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
26. 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.
many-to-one relationship
range
delete()
values(*fields)
27. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
all()
ForeignKey
Manager methods
==
28. Lookup type for date/datetime fields that finds a 'day of the week' match.
help_text
aggregate(args - *kwargs)
|
week_day
29. This field is added automatically - but this behavior can be overridden
intermediate models
relationship spanning
id field
count()
30. 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
31. 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.
gte
lte
model
values_list(*fields)
32. The default for this is the name of the child class followed by '_set'.
Many-to-many relationship to self
delete()
reverse name
iteration
33. This gives your model metadata.
Meta class
iteration
exists()
defer(*fields)
34. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode
Abstract base class
==
MultipleObjectsReturned
count()
35. Disjunction operator for Q objects.
|
count()
lte
QuerySet
36. Returns the object matching the given lookup parameters
filter(**kwargs)
id field
db
get(**kwargs)
37. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
year
Abstract base class
exclude(**kwargs)
~
38. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
get_or_create(**kwargs)
Many-to-many relationship to self
distinct()
~
39. Conjuntion operator for Q objects.
unique
&
null
__unicode__()
40. Lookup type that returns results in a given list.
==
Entry.objects.filter(pub_date__range=(start_date - end_date))
help_text
in
41. These methods are intended to do "table-wide" things.
through argument
Manager methods
lt
model
42. Lookup type that returns results with a case-sensitive end sequence.
help_text
~
endswith
save()
43. (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.
when you add new apps to INSTALLED_APPS
isnull
Restrictions on field names
update()
44. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
|
iendswith
all()
many-to-many relationship
45. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
all()
order_by(*fields)
Q(question__istartswith='What')
iteration
46. Lookup type that returns results with a case-sensitive start sequence.
startswith
aggregate(args - *kwargs)
filter chaining
Q()
47. 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
class type
select_related()
Model metadata
Proxy model
48. When to run syncdb
filter chaining
when you add new apps to INSTALLED_APPS
reverse()
get_absolute_url()
49. 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.
only(*fields)
in
Multi-table inheritance
aggregate(args - *kwargs)
50. If this option is True - the field is allowed to be blank. Default is False.
Model metadata
range
get(**kwargs)
blank