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. Exception raised by get(**kwargs) if no items match the query.
none()
DoesNotExist
MultipleObjectsReturned
blank
2. Lookup type that returns results less than a given value.
Manager
unique
istartswith
lt
3. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
get(**kwargs)
OneToOneField
range
4. Lookup type for date/datetime fields that finds a 'day of the week' match.
iterator()
gt
exists()
week_day
5. 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.
exact
Manager
Many-to-many relationship through an intermediate model
default
6. Manager method used to retrieve every object in a model.
all()
choices
~
reverse name
7. These methods are intended to do "table-wide" things.
OneToOneField
Manager methods
Abstract base class
|
8. 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.
using(alias)
defer(*fields)
distinct()
reverse()
9. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
values_list(*fields)
QuerySet
using(alias)
10. Lookup type that returns results less than or equal to a given value.
ManyToManyField
lte
select_related()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
11. When to run syncdb
count()
Many-to-many relationship to self
relationship spanning
when you add new apps to INSTALLED_APPS
12. This query finds all entries with an id in the list [1 - 3 - 4]
using(alias)
slicing
Entry.objects.filter(id__in=[1 - 3 - 4])
relationship spanning
13. A convenience method for constructing an object and saving it all in one step.
add()
many-to-many relationship
values(*fields)
create(**kwargs)
14. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
annotate(args - *kwargs)
contains
filter chaining
15. a QuerySet can be sliced - using Python's array-slicing syntax.
iteration
slicing
get_or_create(**kwargs)
istartswith
16. 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.
save()
all()
evaluation
exact
17. 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.
Restrictions on field names
delete()
Custom model methods
search
18. If True - the table does not permit duplicate values for this field.
unique
exclude(**kwargs)
in
~
19. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
DoesNotExist
blank
choices tuple
20. Lookup type that finds a case-insensitive regular expression match.
Entry.objects.filter(pub_date__range=(start_date - end_date))
DoesNotExist
Field lookups
iregex
21. Lookup type that returns results with a case-sensitive end sequence.
pk
endswith
gt
get_or_create(**kwargs)
22. Conjuntion operator for Q objects.
&
Custom model methods
select_related()
class type
23. 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.
get(**kwargs)
choices tuple
&
id field
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)
Manager
Model metadata
defer(*fields)
id field
25. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
one-to-one relationship
latest(field_name=None)
exclude(**kwargs)
all()
26. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
class attributes
pk
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
related_name
27. Lookup type that tests for inclusion in a case-sensitive fashion.
Model metadata
QuerySet
contains
Entry.objects.filter(pub_date__year=2005).delete()
28. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
startswith
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
istartswith
==
29. 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.
day
lte
db
values_list(*fields)
30. 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
pk
ordered
values_list(*fields)
exists()
31. Lookup type that returns results with a case-insensitive end sequence.
istartswith
default
iendswith
update()
32. Can be used to remove all many-to-many relationships for an instance
choices
search
filter(**kwargs)
clear() method
33. This model method is used for updating a ManyToManyField.
add()
in
startswith
pickling
34. 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.
exists()
choices
Many-to-many relationship to self
null
35. Lookup type that returns results that fall into an inclusive date range.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
all()
range
__unicode__()
36. 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.
Q()
startswith
Proxy model
Restrictions on field names
37. The database that will be used if this query is executed now
Proxy model
db
ManyToManyField
none()
38. 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.
gt
day
order_by(*fields)
Entry.objects.filter(id__gt=4)
39. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
exact
one-to-one relationship
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
pickling
40. A convenience method for looking up an object with the given kwargs - creating one if necessary.
MultipleObjectsReturned
get_or_create(**kwargs)
contains
lt
41. 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-one relationship
pk
default
Many-to-many relationship through an intermediate model
42. 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
defer(*fields)
primary_key
filter
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
43. This gives your model metadata.
search
Meta class
dates(field - kind - order='ASC')
Many-to-many relationship through an intermediate model
44. Lookup type that finds a case-sensitive regular expression match.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
using(alias)
id field
regex
45. Negation operator for Q objects.
year
Multi-table inheritance
OneToOneField
~
46. Exception raised by get(**kwargs) if more than one item matches the query.
id field
default
MultipleObjectsReturned
filter
47. This is a criterion that narrow down a QuerySet based on given parameters.
in_bulk(id_list)
select_related()
filter
related_name
48. Lookup type that returns results with a case-sensitive start sequence.
~
evaluation
startswith
db
49. 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
Custom model methods
Proxy model
Manager
Many-to-many relationship through an intermediate model
50. 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.
Model metadata
annotate(args - *kwargs)
update()
select_related()