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 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.
order_by(*fields)
ordered
default
blank
2. The database that will be used if this query is executed now
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
in
db
annotate(args - *kwargs)
3. This query finds all entries with an id in the list [1 - 3 - 4]
delete()
values(*fields)
Entry.objects.filter(id__in=[1 - 3 - 4])
Restrictions on field names
4. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
iterator()
ordered
Restrictions on field names
pickling
5. 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.
month
iterator()
Q()
reverse name
6. 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.
Model metadata
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get_absolute_url()
7. a QuerySet can be sliced - using Python's array-slicing syntax.
Manager
istartswith
slicing
~
8. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Abstract base class
==
Q()
choices
9. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
update()
defer(*fields)
id field
delete()
10. (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.
many-to-many relationship
many-to-one relationship
Restrictions on field names
distinct()
11. 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.
many-to-one relationship
choices tuple
__unicode__()
create(**kwargs)
12. 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
13. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
evaluation
isnull
Q()
exclude(**kwargs)
14. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
add()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
__unicode__()
many-to-many relationship
15. Lookup type for date/datetime fields that finds a 'day of the week' match.
ManyToManyField
week_day
OneToOneField
null
16. 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.
values(*fields)
get(**kwargs)
range
Manager
17. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
Many-to-many relationship through an intermediate model
one-to-one relationship
Q(question__istartswith='What')
latest(field_name=None)
18. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Model metadata
exclude(**kwargs)
Many-to-many relationship through an intermediate model
unique
19. 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
20. Lookup type for date/datetime fields that finds an exact day match.
select_related()
iexact
iterator()
day
21. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th
day
reverse name
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
exists()
22. 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
23. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
Restrictions on field names
model
update(**kwargs)
|
24. 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.
unique
db
search
id field
25. Lookup type that returns results greater than a given value.
class attributes
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
gt
class type
26. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
through argument
values(*fields)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Manager
27. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
add()
month
reverse()
iregex
28. Returns the most recent object in the table - by date - using the field_name provided as the date field.
pickling
all()
delete()
latest(field_name=None)
29. This method immediately deletes the object and has no return value.
istartswith
delete()
range
gt
30. Lookup type that returns results greater than or equal to a given value.
week_day
aggregate(args - *kwargs)
values_list(*fields)
gte
31. This model method is used for updating a ManyToManyField.
add()
~
latest(field_name=None)
endswith
32. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
OneToOneField
related_name
update(**kwargs)
one-to-one relationship
33. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Restrictions on field names
Custom model methods
annotate(args - *kwargs)
through argument
34. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
intermediate models
latest(field_name=None)
35. If True - this field is the primary key for the model.
primary_key
ForeignKey
exclude(**kwargs)
using(alias)
36. A convenience method for looking up an object with the given kwargs - creating one if necessary.
contains
primary_key
aggregate(args - *kwargs)
get_or_create(**kwargs)
37. Lookup type that returns results with a case-insensitive end sequence.
iendswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
OneToOneField
Entry.objects.filter(id__in=[1 - 3 - 4])
38. 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.
exists()
endswith
many-to-one relationship
Field lookups
39. Lookup type that returns results with a case-insensitive start sequence.
ManyToManyField
istartswith
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
gte
40. This represents a collection of objects from your database. It can have zero - one or many filters.
pk
gte
ManyToManyField
QuerySet
41. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
in_bulk(id_list)
iexact
Entry.objects.filter(id__gt=4)
F()
42. A Python "magic method" that returns a unicode "representation" of any object.
many-to-many relationship
reverse name
__unicode__()
Entry.objects.filter(pub_date__year=2005).delete()
43. 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
relationship spanning
add()
Manager methods
dates(field - kind - order='ASC')
44. 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.
pickling
reverse()
get_or_create(**kwargs)
iexact
45. 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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
&
pk
none()
46. 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.
iexact
Multi-table inheritance
help_text
get_or_create(**kwargs)
47. These methods are intended to do "table-wide" things.
Manager methods
defer(*fields)
lte
istartswith
48. Lookup type that returns results in a given list.
day
ordered
in
exists()
49. Manager method used to retrieve every object in a model.
all()
class attributes
MultipleObjectsReturned
relationship spanning
50. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
Q(question__istartswith='What')
|
lte