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. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
when you add new apps to INSTALLED_APPS
Many-to-many relationship through an intermediate model
ordered
iteration
2. 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.
iexact
ManyToManyField
search
istartswith
3. 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
4. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
gte
db
values_list(*fields)
related_name
5. 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
6. 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
7. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)
filter(**kwargs)
Model metadata
Proxy model
Restrictions on field names
8. This model method is used for updating a ManyToManyField.
add()
Model metadata
reverse name
filter
9. 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
10. Lookup type that returns results greater than or equal to a given value.
id field
many-to-many relationship
OneToOneField
gte
11. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
Manager methods
relationship spanning
get(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
12. 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.
iterator()
contains
default
delete()
13. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
exists()
DoesNotExist
count()
gt
14. If True - the table does not permit duplicate values for this field.
unique
istartswith
get(**kwargs)
many-to-one relationship
15. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Field lookups
class type
16. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
Entry.objects.filter(pub_date__range=(start_date - end_date))
get_absolute_url()
Abstract base class
17. 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.
select_related()
update(**kwargs)
many-to-one relationship
Many-to-many relationship to self
18. Lookup type for date/datetime fields that finds an exact day match.
day
choices tuple
Custom model methods
iterator()
19. 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
isnull
Abstract base class
all()
exact
20. 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
none()
in_bulk(id_list)
week_day
update(**kwargs)
21. To activate your models
ForeignKey
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
lt
QuerySet
22. (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.
Manager methods
Restrictions on field names
==
primary_key
23. The database that will be used if this query is executed now
primary_key
db
F()
iteration
24. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
latest(field_name=None)
only(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
25. This query finds all entries with an id greater than 4.
evaluation
Many-to-many relationship through an intermediate model
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Entry.objects.filter(id__gt=4)
26. This represents a collection of objects from your database. It can have zero - one or many filters.
Q()
many-to-one relationship
reverse name
QuerySet
27. Lookup type that returns results less than or equal to a given value.
Manager
lte
choices
iexact
28. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Proxy model
__unicode__()
29. 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
lt
many-to-many relationship
istartswith
30. Can be used to remove all many-to-many relationships for an instance
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
reverse name
clear() method
model
31. 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.
choices tuple
update(**kwargs)
in_bulk(id_list)
ManyToManyField
32. Lookup type that returns results that fall into an inclusive date range.
range
class type
Manager
gt
33. Lookup type that returns results greater than a given value.
iregex
class attributes
gt
gte
34. 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.
regex
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
filter chaining
values_list(*fields)
35. This field is added automatically - but this behavior can be overridden
pickling
id field
~
many-to-one relationship
36. Lookup type that finds a case-sensitive regular expression match.
iregex
choices tuple
~
regex
37. Keyword shortcut for looking up an object by primary key.
pk
Manager
select_related()
gte
38. 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.
select_related()
exact
Q(question__istartswith='What')
gt
39. Returns the object matching the given lookup parameters
get(**kwargs)
db
Manager
class attributes
40. 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
choices tuple
select_related()
==
evaluation
41. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
istartswith
Proxy model
order_by(*fields)
42. 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
ManyToManyField
Proxy model
month
Abstract base class
43. Returns the most recent object in the table - by date - using the field_name provided as the date field.
in_bulk(id_list)
Custom model methods
regex
latest(field_name=None)
44. The default for this is the name of the child class followed by '_set'.
reverse name
ForeignKey
exists()
Manager methods
45. 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.
annotate(args - *kwargs)
~
Entry.objects.filter(pub_date__range=(start_date - end_date))
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
46. 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
Meta class
using(alias)
when you add new apps to INSTALLED_APPS
annotate(args - *kwargs)
47. 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
Restrictions on field names
Meta class
Many-to-many relationship to self
48. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
add()
iteration
reverse name
49. 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.
iregex
pickling
choices
Model metadata
50. 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
dates(field - kind - order='ASC')
Field lookups
relationship spanning
exists()