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. 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
contains
iterator()
&
using(alias)
2. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
dates(field - kind - order='ASC')
Entry.objects.filter(pub_date__year=2005).delete()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
3. Lookup type that tests for inclusion in a case-sensitive fashion.
evaluation
gte
choices tuple
contains
4. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
Q(question__istartswith='What')
help_text
in
5. A convenience method for looking up an object with the given kwargs - creating one if necessary.
evaluation
get_or_create(**kwargs)
only(*fields)
choices tuple
6. 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
add()
Abstract base class
aggregate(args - *kwargs)
regex
7. 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.
order_by(*fields)
default
isnull
through argument
8. This is a criterion that narrow down a QuerySet based on given parameters.
range
filter
Restrictions on field names
delete()
9. This represents a collection of objects from your database. It can have zero - one or many filters.
get_or_create(**kwargs)
QuerySet
filter(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
10. This query finds all entries between a start date of start_date and an end date of end_date.
ordered
Entry.objects.filter(pub_date__range=(start_date - end_date))
startswith
gt
11. 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)
istartswith
Entry.objects.filter(pub_date__year=2005).delete()
~
Model metadata
12. 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.
aggregate(args - *kwargs)
blank
exists()
exact
13. 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
create(**kwargs)
relationship spanning
Manager
in_bulk(id_list)
14. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
intermediate models
delete()
Abstract base class
15. Exception raised by get(**kwargs) if no items match the query.
id field
DoesNotExist
ManyToManyField
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
16. 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.
search
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(id__in=[1 - 3 - 4])
class type
17. This model method is used for updating a ManyToManyField.
evaluation
add()
month
update(**kwargs)
18. If this option is True - Django will store empty values as NULL in the database. Default is False.
relationship spanning
null
Model metadata
Multi-table inheritance
19. If True - this field is the primary key for the model.
Proxy model
select_related()
primary_key
day
20. When to run syncdb
when you add new apps to INSTALLED_APPS
one-to-one relationship
in_bulk(id_list)
update()
21. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
in_bulk(id_list)
db
pk
22. 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.
one-to-one relationship
reverse()
exact
exclude(**kwargs)
23. a QuerySet can be sliced - using Python's array-slicing syntax.
related_name
lt
delete()
slicing
24. Lookup type that returns results less than a given value.
get(**kwargs)
week_day
one-to-one relationship
lt
25. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
class type
Many-to-many relationship through an intermediate model
Entry.objects.filter(id__gt=4)
one-to-one relationship
26. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
|
filter
Multi-table inheritance
27. This model method saves a model instance to the database. This method has no return value.
range
iendswith
save()
istartswith
28. Used to get a QuerySet for a model. This is called 'objects' by default.
in
year
Manager
Meta class
29. 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
values_list(*fields)
annotate(args - *kwargs)
null
Q()
30. Returns the object matching the given lookup parameters
get(**kwargs)
Field lookups
unique
day
31. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
week_day
values_list(*fields)
null
32. This query finds all entries with an id greater than 4.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Q(question__istartswith='What')
Entry.objects.filter(id__gt=4)
exists()
33. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
Multi-table inheritance
reverse name
F()
filter chaining
34. Performs an SQL update query for the specified fields - and returns the number of rows affected. This method is applied instantly and the only restriction on the QuerySet that is updated is that it can only update columns in the model's main table. F
update(**kwargs)
Many-to-many relationship through an intermediate model
Entry.objects.filter(pub_date__range=(start_date - end_date))
exists()
35. 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.
Custom model methods
count()
delete()
update()
36. (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.
month
Restrictions on field names
add()
intermediate models
37. Lookup type that returns results greater than a given value.
isnull
reverse()
gt
Q(question__istartswith='What')
38. 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.
using(alias)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
filter
model
39. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
iexact
through argument
one-to-one relationship
40. Lookup type that returns results that fall into an inclusive date range.
clear() method
filter(**kwargs)
range
Manager methods
41. Lookup type that returns results with a case-insensitive start sequence.
iexact
update()
istartswith
Entry.objects.filter(id__in=[1 - 3 - 4])
42. 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.
iterator()
help_text
ForeignKey
delete()
43. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
many-to-one relationship
iteration
range
add()
44. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
primary_key
aggregate(args - *kwargs)
gt
exclude(**kwargs)
45. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
get(**kwargs)
F()
class attributes
46. 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
only(*fields)
Many-to-many relationship through an intermediate model
filter chaining
ManyToManyField
47. Lookup type that finds a case-sensitive regular expression match.
Meta class
distinct()
exists()
regex
48. 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.
filter chaining
day
through argument
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
49. 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
MultipleObjectsReturned
iexact
order_by(*fields)
50. 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
class type
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
using(alias)
gt