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. 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.
filter
ManyToManyField
save()
isnull
2. 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.
id field
filter chaining
year
iteration
3. These methods are intended to do "table-wide" things.
istartswith
Manager methods
isnull
__unicode__()
4. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
lt
QuerySet
defer(*fields)
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. Returns the object matching the given lookup parameters
get(**kwargs)
one-to-one relationship
regex
Q()
7. 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.
delete()
exact
Field lookups
get_or_create(**kwargs)
8. Conjuntion operator for Q objects.
intermediate models
day
&
gte
9. Lookup type that yields a case-insensitive match.
iexact
QuerySet
exists()
in
10. 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
dates(field - kind - order='ASC')
only(*fields)
none()
choices
11. Lookup type that returns results in a given list.
when you add new apps to INSTALLED_APPS
lte
in
isnull
12. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
Many-to-many relationship through an intermediate model
order_by(*fields)
in_bulk(id_list)
choices
13. Lookup type that finds a case-insensitive regular expression match.
iregex
aggregate(args - *kwargs)
Many-to-many relationship through an intermediate model
Entry.objects.filter(pub_date__year=2005).delete()
14. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
order_by(*fields)
iendswith
iteration
Field lookups
15. 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.
class type
pickling
aggregate(args - *kwargs)
exact
16. 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
annotate(args - *kwargs)
exists()
QuerySet
ManyToManyField
17. 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.
model
filter(**kwargs)
get_absolute_url()
pickling
18. This represents a collection of objects from your database. It can have zero - one or many filters.
Manager
QuerySet
Model metadata
istartswith
19. 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
~
add()
in_bulk(id_list)
select_related()
20. Lookup type that returns results with a case-insensitive start sequence.
default
istartswith
id field
exclude(**kwargs)
21. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
defer(*fields)
Model metadata
count()
help_text
22. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
iendswith
DoesNotExist
using(alias)
23. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
iterator()
iregex
QuerySet
one-to-one relationship
24. 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.
month
F()
get_absolute_url()
Entry.objects.filter(pub_date__year=2005).delete()
25. Lookup type that tests for inclusion in a case-sensitive fashion.
defer(*fields)
related_name
contains
isnull
26. 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
__unicode__()
clear() method
27. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
clear() method
isnull
get(**kwargs)
Field lookups
28. a QuerySet can be sliced - using Python's array-slicing syntax.
model
create(**kwargs)
slicing
defer(*fields)
29. 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.
week_day
QuerySet
order_by(*fields)
Many-to-many relationship through an intermediate model
30. To activate your models
Field lookups
get(**kwargs)
get_or_create(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
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.
in_bulk(id_list)
Proxy model
choices tuple
delete()
32. 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.
all()
F()
update()
Multi-table inheritance
33. 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.
OneToOneField
using(alias)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Field lookups
34. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Q()
|
default
many-to-many relationship
35. Lookup type that returns results that fall into an inclusive date range.
filter(**kwargs)
year
range
exclude(**kwargs)
36. 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.
search
~
latest(field_name=None)
order_by(*fields)
37. If this option is True - the field is allowed to be blank. Default is False.
gte
|
reverse()
blank
38. Keyword shortcut for looking up an object by primary key.
pk
day
Custom model methods
year
39. (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.
Field lookups
Restrictions on field names
regex
Multi-table inheritance
40. 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(id__in=[1 - 3 - 4])
pickling
41. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
get_or_create(**kwargs)
search
OneToOneField
42. 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)
choices
Manager methods
regex
43. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
Entry.objects.filter(id__in=[1 - 3 - 4])
&
null
44. Lookup type that returns results with a case-insensitive end sequence.
startswith
using(alias)
iendswith
select_related()
45. Exception raised by get(**kwargs) if more than one item matches the query.
year
MultipleObjectsReturned
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
lte
46. 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
values_list(*fields)
Multi-table inheritance
==
through argument
47. 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
pickling
Custom model methods
relationship spanning
Entry.objects.filter(pub_date__range=(start_date - end_date))
48. This query deletes all Entry objects with a pub_date year of 2005.
MultipleObjectsReturned
order_by(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
Many-to-many relationship to self
49. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
id field
regex
all()
year
50. This model method is used for updating a ManyToManyField.
ordered
filter(**kwargs)
add()
dates(field - kind - order='ASC')