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. Negation operator for Q objects.
lte
~
defer(*fields)
Manager
2. 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
&
day
through argument
select_related()
3. 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.
endswith
iregex
update()
order_by(*fields)
4. Disjunction operator for Q objects.
exact
intermediate models
null
|
5. 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.
many-to-many relationship
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
clear() method
aggregate(args - *kwargs)
6. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
Manager methods
add()
unique
7. Fields are specified by these
ordered
class attributes
defer(*fields)
lte
8. 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
Q(question__istartswith='What')
Abstract base class
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
select_related()
9. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
in
==
all()
startswith
10. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
get_or_create(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
isnull
__unicode__()
11. Lookup type that returns results with a case-sensitive end sequence.
iteration
endswith
search
gte
12. This gives your model metadata.
save()
slicing
Q()
Meta class
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
gt
dates(field - kind - order='ASC')
model
annotate(args - *kwargs)
14. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
pk
through argument
all()
15. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
iregex
only(*fields)
month
delete()
16. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
db
Model metadata
model
year
17. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
many-to-one relationship
values(*fields)
endswith
18. Lookup type that finds a case-insensitive regular expression match.
&
iregex
week_day
aggregate(args - *kwargs)
19. (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.
iterator()
many-to-one relationship
Restrictions on field names
id field
20. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire
Multi-table inheritance
annotate(args - *kwargs)
day
iterator()
21. This query finds all entries between a start date of start_date and an end date of end_date.
ForeignKey
evaluation
Entry.objects.filter(pub_date__range=(start_date - end_date))
Proxy model
22. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
exists()
distinct()
range
23. 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
24. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
isnull
Restrictions on field names
related_name
25. Lookup type for date/datetime fields that finds an exact day match.
relationship spanning
count()
through argument
day
26. 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
iendswith
ManyToManyField
|
none()
27. This query finds all entries with an id in the list [1 - 3 - 4]
update(**kwargs)
choices tuple
Entry.objects.filter(id__in=[1 - 3 - 4])
istartswith
28. 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.
values_list(*fields)
Q()
lt
filter(**kwargs)
29. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
evaluation
__unicode__()
model
blank
30. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
save()
ordered
unique
aggregate(args - *kwargs)
31. 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.
Multi-table inheritance
values_list(*fields)
none()
exclude(**kwargs)
32. 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.
exact
in
get(**kwargs)
choices
33. If this option is True - Django will store empty values as NULL in the database. Default is False.
ManyToManyField
delete()
reverse()
null
34. When to run syncdb
iendswith
null
annotate(args - *kwargs)
when you add new apps to INSTALLED_APPS
35. Lookup type that returns results with a case-sensitive start sequence.
==
defer(*fields)
startswith
null
36. 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
get_absolute_url()
__unicode__()
using(alias)
37. 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.
Entry.objects.filter(id__gt=4)
choices tuple
lt
values_list(*fields)
38. Exception raised by get(**kwargs) if more than one item matches the query.
model
values(*fields)
reverse name
MultipleObjectsReturned
39. 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.
filter(**kwargs)
reverse()
choices tuple
Q(question__istartswith='What')
40. 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.
many-to-many relationship
pickling
filter(**kwargs)
Manager
41. 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.
latest(field_name=None)
MultipleObjectsReturned
clear() method
using(alias)
42. A convenience method for looking up an object with the given kwargs - creating one if necessary.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_or_create(**kwargs)
ordered
get_absolute_url()
43. Manager method used to retrieve every object in a model.
all()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
select_related()
Multi-table inheritance
44. 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
45. 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
reverse()
choices
exists()
defer(*fields)
46. If True - this field is the primary key for the model.
using(alias)
primary_key
iterator()
==
47. Lookup type that returns results with a case-insensitive end sequence.
pickling
istartswith
Entry.objects.filter(pub_date__range=(start_date - end_date))
iendswith
48. Keyword shortcut for looking up an object by primary key.
class type
range
when you add new apps to INSTALLED_APPS
pk
49. 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.
iteration
slicing
delete()
50. Used to get a QuerySet for a model. This is called 'objects' by default.
Abstract base class
OneToOneField
Manager
ForeignKey