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 database that will be used if this query is executed now
MultipleObjectsReturned
delete()
db
|
2. Lookup type for date/datetime fields that finds a 'day of the week' match.
ManyToManyField
delete()
week_day
__unicode__()
3. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
get_absolute_url()
clear() method
|
4. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
select_related()
many-to-many relationship
in
5. 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.
iterator()
pickling
choices tuple
year
6. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
reverse()
class attributes
iteration
Multi-table inheritance
7. 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
8. 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.
day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(id__in=[1 - 3 - 4])
in_bulk(id_list)
9. 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
Model metadata
values(*fields)
relationship spanning
year
10. Fields are specified by these
many-to-many relationship
~
related_name
class attributes
11. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
Entry.objects.filter(pub_date__range=(start_date - end_date))
isnull
Manager
when you add new apps to INSTALLED_APPS
12. 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
13. Lookup type that returns results that fall into an inclusive date range.
add()
Abstract base class
Multi-table inheritance
range
14. Keyword shortcut for looking up an object by primary key.
none()
only(*fields)
pk
get_absolute_url()
15. 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
contains
select_related()
istartswith
OneToOneField
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.
regex
model
in
istartswith
17. Lookup type that yields a case-insensitive match.
exists()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
using(alias)
iexact
18. 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.
none()
only(*fields)
get_absolute_url()
gte
19. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
evaluation
&
gt
20. If this option is True - Django will store empty values as NULL in the database. Default is False.
MultipleObjectsReturned
null
model
defer(*fields)
21. 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
create(**kwargs)
through argument
only(*fields)
get_absolute_url()
22. Can be used to remove all many-to-many relationships for an instance
delete()
many-to-many relationship
ordered
clear() method
23. 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.
order_by(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
month
filter chaining
24. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
using(alias)
many-to-many relationship
filter(**kwargs)
month
25. 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
order_by(*fields)
none()
iteration
Entry.objects.filter(id__gt=4)
26. These methods are intended to do "table-wide" things.
latest(field_name=None)
range
distinct()
Manager methods
27. 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
28. Lookup type that finds a case-insensitive regular expression match.
Custom model methods
iregex
related_name
when you add new apps to INSTALLED_APPS
29. This field is added automatically - but this behavior can be overridden
all()
update()
QuerySet
id field
30. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
lt
null
clear() method
31. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()
evaluation
exclude(**kwargs)
in_bulk(id_list)
delete()
32. The default for this is the name of the child class followed by '_set'.
get_absolute_url()
week_day
iterator()
reverse name
33. If this option is True - the field is allowed to be blank. Default is False.
get(**kwargs)
~
through argument
blank
34. a QuerySet can be sliced - using Python's array-slicing syntax.
range
delete()
MultipleObjectsReturned
slicing
35. When to run syncdb
exists()
==
when you add new apps to INSTALLED_APPS
evaluation
36. Lookup type for date/datetime fields that finds an exact day match.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
default
day
add()
37. 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.
Custom model methods
exact
Entry.objects.filter(id__in=[1 - 3 - 4])
Restrictions on field names
38. Exception raised by get(**kwargs) if more than one item matches the query.
get(**kwargs)
Restrictions on field names
MultipleObjectsReturned
year
39. 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.
Multi-table inheritance
delete()
isnull
in
40. 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.
default
when you add new apps to INSTALLED_APPS
Q()
startswith
41. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
Custom model methods
slicing
one-to-one relationship
42. 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
__unicode__()
exists()
reverse name
db
43. 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.
exclude(**kwargs)
null
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
~
44. Negation operator for Q objects.
~
iterator()
in
distinct()
45. 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.
QuerySet
search
select_related()
week_day
46. This gives your model metadata.
range
using(alias)
Meta class
reverse()
47. 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.
one-to-one relationship
isnull
OneToOneField
filter(**kwargs)
48. 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.
month
pickling
DoesNotExist
==
49. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Abstract base class
slicing
clear() method
exclude(**kwargs)
50. 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
filter(**kwargs)
annotate(args - *kwargs)
Q(question__istartswith='What')
default