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. Lookup type that returns results greater than a given value.
gt
using(alias)
F()
id field
2. Fields are specified by these
class attributes
exclude(**kwargs)
db
delete()
3. 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.
when you add new apps to INSTALLED_APPS
add()
year
aggregate(args - *kwargs)
4. This field is added automatically - but this behavior can be overridden
Model metadata
latest(field_name=None)
~
id field
5. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
annotate(args - *kwargs)
month
one-to-one relationship
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
6. 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
7. 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.
&
in_bulk(id_list)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get(**kwargs)
8. 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
Entry.objects.filter(id__in=[1 - 3 - 4])
Entry.objects.filter(pub_date__year=2005).delete()
all()
9. 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.
ordered
filter
choices
exclude(**kwargs)
10. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Restrictions on field names
class type
many-to-many relationship
update()
11. These add custom "row-level" functionality to your objects. These act on a particular model instance.
model
Custom model methods
Entry.objects.filter(pub_date__year=2005).delete()
iexact
12. Lookup type that returns results with a case-insensitive end sequence.
help_text
slicing
iendswith
aggregate(args - *kwargs)
13. If this option is True - the field is allowed to be blank. Default is False.
OneToOneField
blank
Entry.objects.filter(pub_date__range=(start_date - end_date))
none()
14. Lookup type that returns results with a case-sensitive end sequence.
reverse name
endswith
delete()
dates(field - kind - order='ASC')
15. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
Q(question__istartswith='What')
iterator()
intermediate models
16. Lookup type for date/datetime fields that finds a 'day of the week' match.
annotate(args - *kwargs)
all()
pickling
week_day
17. This query deletes all Entry objects with a pub_date year of 2005.
istartswith
select_related()
get_absolute_url()
Entry.objects.filter(pub_date__year=2005).delete()
18. This method immediately deletes the object and has no return value.
iteration
exists()
delete()
iterator()
19. 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.
dates(field - kind - order='ASC')
default
Manager methods
filter
20. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
all()
iterator()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
21. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
in
through argument
istartswith
22. 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
iterator()
only(*fields)
null
__unicode__()
23. 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
24. 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)
Model metadata
delete()
Proxy model
annotate(args - *kwargs)
25. 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.
all()
iterator()
choices
filter chaining
26. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Field lookups
|
==
27. Lookup type that returns results less than a given value.
class attributes
lt
Proxy model
day
28. If True - this field is the primary key for the model.
Many-to-many relationship to self
Model metadata
search
primary_key
29. This model method saves a model instance to the database. This method has no return value.
delete()
save()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
latest(field_name=None)
30. 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.
class type
get(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
iregex
31. 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
reverse()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
endswith
class type
32. Can be used to remove all many-to-many relationships for an instance
clear() method
get(**kwargs)
many-to-many relationship
all()
33. Lookup type that returns results with a case-sensitive start sequence.
filter chaining
primary_key
startswith
~
34. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
istartswith
class type
exclude(**kwargs)
model
35. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
help_text
defer(*fields)
reverse name
36. 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.
save()
DoesNotExist
search
QuerySet
37. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
Meta class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
one-to-one relationship
38. This query finds all entries with an id greater than 4.
filter
Entry.objects.filter(id__gt=4)
select_related()
gt
39. 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.
exclude(**kwargs)
values_list(*fields)
update()
distinct()
40. Conjuntion operator for Q objects.
model
when you add new apps to INSTALLED_APPS
&
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
41. This represents a collection of objects from your database. It can have zero - one or many filters.
order_by(*fields)
QuerySet
values(*fields)
range
42. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
isnull
Manager methods
delete()
43. 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.
all()
iregex
get_absolute_url()
db
44. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
iendswith
Model metadata
Entry.objects.filter(id__gt=4)
45. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Manager
filter(**kwargs)
order_by(*fields)
__unicode__()
46. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
regex
day
~
47. 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.
class type
Entry.objects.filter(id__in=[1 - 3 - 4])
pk
pickling
48. 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.
unique
ordered
pickling
reverse()
49. Lookup type that returns results greater than or equal to a given value.
get(**kwargs)
gte
Many-to-many relationship through an intermediate model
filter
50. 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()
id field
evaluation
filter chaining
Q(question__istartswith='What')