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 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.
many-to-many relationship
Q()
QuerySet
Multi-table inheritance
2. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exact
none()
ordered
3. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
get_or_create(**kwargs)
help_text
week_day
count()
4. Keyword shortcut for looking up an object by primary key.
pk
Q()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
isnull
5. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
iterator()
many-to-one relationship
related_name
all()
6. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
when you add new apps to INSTALLED_APPS
choices tuple
add()
update()
7. Lookup type for date/datetime fields that finds a 'day of the week' match.
filter(**kwargs)
exists()
create(**kwargs)
week_day
8. 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.
Field lookups
order_by(*fields)
Q()
gt
9. 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
F()
search
Abstract base class
delete()
10. This query finds all entries with an id greater than 4.
help_text
Many-to-many relationship to self
values_list(*fields)
Entry.objects.filter(id__gt=4)
11. 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.
ForeignKey
Manager
filter chaining
iexact
12. 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.
select_related()
get_or_create(**kwargs)
reverse()
get_absolute_url()
13. 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
Field lookups
slicing
annotate(args - *kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
14. These methods are intended to do "table-wide" things.
Manager methods
update(**kwargs)
id field
dates(field - kind - order='ASC')
15. Conjuntion operator for Q objects.
&
aggregate(args - *kwargs)
iexact
iendswith
16. 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
Many-to-many relationship through an intermediate model
F()
related_name
select_related()
17. This is a criterion that narrow down a QuerySet based on given parameters.
exclude(**kwargs)
filter
annotate(args - *kwargs)
update()
18. 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
choices
class type
exclude(**kwargs)
Field lookups
19. A convenience method for looking up an object with the given kwargs - creating one if necessary.
related_name
Entry.objects.filter(pub_date__range=(start_date - end_date))
get_or_create(**kwargs)
all()
20. Lookup type that returns results with a case-insensitive end sequence.
related_name
using(alias)
iendswith
default
21. 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()
exists()
one-to-one relationship
get_absolute_url()
22. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_or_create(**kwargs)
get(**kwargs)
regex
23. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Many-to-many relationship through an intermediate model
one-to-one relationship
iendswith
Entry.objects.filter(id__gt=4)
24. 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
many-to-many relationship
OneToOneField
relationship spanning
25. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
search
all()
relationship spanning
26. 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
only(*fields)
Multi-table inheritance
choices
week_day
27. Can be used to remove all many-to-many relationships for an instance
range
in_bulk(id_list)
null
clear() method
28. 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.
values_list(*fields)
filter(**kwargs)
Manager
Field lookups
29. 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
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
F()
db
30. 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.
Many-to-many relationship through an intermediate model
startswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
31. Lookup type that tests for inclusion in a case-sensitive fashion.
exists()
contains
choices tuple
iterator()
32. 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
distinct()
Abstract base class
iterator()
33. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Field lookups
OneToOneField
QuerySet
34. Lookup type for date/datetime fields that finds an exact day match.
Restrictions on field names
get(**kwargs)
Model metadata
day
35. If True - the table does not permit duplicate values for this field.
get(**kwargs)
add()
QuerySet
unique
36. Returns the most recent object in the table - by date - using the field_name provided as the date field.
contains
latest(field_name=None)
update()
Manager methods
37. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
one-to-one relationship
iteration
reverse()
Entry.objects.filter(id__gt=4)
38. Lookup type that returns results with a case-insensitive start sequence.
istartswith
day
related_name
update(**kwargs)
39. Lookup type that finds a case-insensitive regular expression match.
values(*fields)
iterator()
iregex
many-to-many relationship
40. 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
41. This query deletes all Entry objects with a pub_date year of 2005.
unique
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Abstract base class
Entry.objects.filter(pub_date__year=2005).delete()
42. Fields are specified by these
Entry.objects.filter(pub_date__year=2005).delete()
==
class attributes
many-to-many relationship
43. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
iterator()
order_by(*fields)
regex
distinct()
44. 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.
defer(*fields)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
save()
Many-to-many relationship to self
45. This model method is used for updating a ManyToManyField.
delete()
add()
null
ManyToManyField
46. This model method saves a model instance to the database. This method has no return value.
pickling
day
Proxy model
save()
47. Lookup type that returns results greater than or equal to a given value.
add()
gte
exact
through argument
48. 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
49. Disjunction operator for Q objects.
|
Manager
reverse()
primary_key
50. (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.
through argument
Manager
default
Restrictions on field names