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. The default for this is the name of the child class followed by '_set'.
model
reverse name
Entry.objects.filter(pub_date__year=2005).delete()
exact
2. 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)
get(**kwargs)
iteration
MultipleObjectsReturned
3. 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.
ManyToManyField
get(**kwargs)
month
evaluation
4. 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
Entry.objects.filter(pub_date__year=2005).delete()
delete()
iexact
5. 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
|
ManyToManyField
intermediate models
Manager
6. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
Many-to-many relationship through an intermediate model
many-to-one relationship
count()
F()
7. Lookup type that returns results that fall into an inclusive date range.
reverse()
Entry.objects.filter(id__in=[1 - 3 - 4])
range
Field lookups
8. When to run syncdb
QuerySet
get_absolute_url()
startswith
when you add new apps to INSTALLED_APPS
9. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
values(*fields)
in_bulk(id_list)
evaluation
10. 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.
range
create(**kwargs)
pickling
filter
11. 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
Q(question__istartswith='What')
|
id field
only(*fields)
12. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
iterator()
MultipleObjectsReturned
&
13. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
all()
~
ordered
14. This query finds all entries with an id in the list [1 - 3 - 4]
reverse name
exact
Entry.objects.filter(id__in=[1 - 3 - 4])
count()
15. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Multi-table inheritance
exact
many-to-many relationship
iterator()
16. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
get_or_create(**kwargs)
create(**kwargs)
model
count()
17. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
month
select_related()
primary_key
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
related_name
iterator()
__unicode__()
values(*fields)
19. 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
all()
month
Model metadata
slicing
20. This model method saves a model instance to the database. This method has no return value.
range
default
save()
month
21. This method immediately deletes the object and has no return value.
Custom model methods
Manager
delete()
slicing
22. 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()
lte
Meta class
contains
23. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
Restrictions on field names
Q()
DoesNotExist
24. 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
ManyToManyField
none()
F()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
25. 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
choices tuple
Custom model methods
~
26. 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.
one-to-one relationship
default
clear() method
update(**kwargs)
27. 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.
using(alias)
reverse()
unique
F()
28. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
Many-to-many relationship to self
exact
Many-to-many relationship through an intermediate model
29. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get(**kwargs)
in
iterator()
30. (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
Meta class
choices tuple
31. 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
Abstract base class
update(**kwargs)
none()
aggregate(args - *kwargs)
32. 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
33. Lookup type that returns results with a case-insensitive end sequence.
distinct()
blank
in
iendswith
34. Exception raised by get(**kwargs) if more than one item matches the query.
evaluation
MultipleObjectsReturned
select_related()
OneToOneField
35. If True - this field is the primary key for the model.
primary_key
in_bulk(id_list)
search
id field
36. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
model
istartswith
many-to-many relationship
exclude(**kwargs)
37. These methods are intended to do "table-wide" things.
ordered
delete()
Manager methods
values_list(*fields)
38. Negation operator for Q objects.
default
iregex
~
clear() method
39. Lookup type that returns results with a case-sensitive start sequence.
iregex
ManyToManyField
startswith
related_name
40. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used
select_related()
day
|
class type
41. 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.
update(**kwargs)
~
filter(**kwargs)
Q()
42. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
unique
evaluation
distinct()
Field lookups
43. This represents a collection of objects from your database. It can have zero - one or many filters.
search
QuerySet
startswith
__unicode__()
44. Conjuntion operator for Q objects.
&
gte
OneToOneField
choices
45. 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.
db
get_absolute_url()
latest(field_name=None)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
46. Lookup type that returns results less than a given value.
default
lt
choices tuple
null
47. This is a criterion that narrow down a QuerySet based on given parameters.
MultipleObjectsReturned
filter
unique
==
48. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
through argument
Entry.objects.filter(id__gt=4)
intermediate models
49. 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
50. Lookup type that returns results with a case-insensitive start sequence.
update()
iexact
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
istartswith