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. Used to get a QuerySet for a model. This is called 'objects' by default.
db
Field lookups
Custom model methods
Manager
2. This method immediately deletes the object and has no return value.
delete()
only(*fields)
in_bulk(id_list)
Proxy model
3. Lookup type that returns results with a case-insensitive start sequence.
gt
many-to-many relationship
istartswith
select_related()
4. The default for this is the name of the child class followed by '_set'.
unique
filter chaining
get(**kwargs)
reverse name
5. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
none()
get_absolute_url()
month
MultipleObjectsReturned
6. If this option is True - Django will store empty values as NULL in the database. Default is False.
defer(*fields)
null
DoesNotExist
Multi-table inheritance
7. 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
class type
save()
contains
8. Lookup type that returns results greater than or equal to a given value.
help_text
when you add new apps to INSTALLED_APPS
==
gte
9. Defined by django.db.models.ForeignKey. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-one relationship
Entry.objects.filter(pub_date__year=2005).delete()
iexact
exists()
10. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
reverse()
select_related()
day
11. Lookup type for date/datetime fields that finds a 'day of the week' match.
all()
distinct()
week_day
null
12. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
~
one-to-one relationship
month
class attributes
13. 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.
through argument
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
dates(field - kind - order='ASC')
update()
14. 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
choices
default
startswith
15. This field is added automatically - but this behavior can be overridden
one-to-one relationship
regex
choices tuple
id field
16. 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
blank
null
all()
default
17. This represents a collection of objects from your database. It can have zero - one or many filters.
filter
select_related()
Entry.objects.filter(pub_date__year=2005).delete()
QuerySet
18. If this option is True - the field is allowed to be blank. Default is False.
iterator()
Field lookups
blank
annotate(args - *kwargs)
19. This query finds all entries with an id in the list [1 - 3 - 4]
through argument
Entry.objects.filter(id__in=[1 - 3 - 4])
isnull
Q()
20. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
ManyToManyField
exact
Multi-table inheritance
blank
21. 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.
Multi-table inheritance
latest(field_name=None)
Proxy model
aggregate(args - *kwargs)
22. Lookup type that returns results in a given list.
Many-to-many relationship through an intermediate model
in
annotate(args - *kwargs)
aggregate(args - *kwargs)
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. 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)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
through argument
all()
25. 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
26. 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-many relationship through an intermediate model
regex
when you add new apps to INSTALLED_APPS
QuerySet
27. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
slicing
==
isnull
one-to-one relationship
28. 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
filter(**kwargs)
update(**kwargs)
Restrictions on field names
exclude(**kwargs)
29. Lookup type that returns results with a case-insensitive end sequence.
values_list(*fields)
iendswith
Abstract base class
dates(field - kind - order='ASC')
30. 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.
iregex
QuerySet
iteration
in_bulk(id_list)
31. 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
32. Returns the object matching the given lookup parameters
get(**kwargs)
help_text
order_by(*fields)
month
33. 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
relationship spanning
exclude(**kwargs)
one-to-one relationship
__unicode__()
34. Lookup type that returns results with a case-sensitive end sequence.
delete()
search
endswith
Many-to-many relationship through an intermediate model
35. 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
many-to-one relationship
Abstract base class
regex
Proxy model
36. Lookup type that returns results greater than a given value.
delete()
primary_key
gt
clear() method
37. (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.
one-to-one relationship
Restrictions on field names
F()
add()
38. When to run syncdb
F()
exists()
Entry.objects.filter(pub_date__range=(start_date - end_date))
when you add new apps to INSTALLED_APPS
39. Defines a many-to-many relationship. You use it just like any other Field type: by including it as a class attribute of your model.
ManyToManyField
when you add new apps to INSTALLED_APPS
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
aggregate(args - *kwargs)
40. 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
41. 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()
values_list(*fields)
exclude(**kwargs)
Manager methods
42. This gives your model metadata.
gt
Meta class
Multi-table inheritance
exact
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.
Field lookups
select_related()
get_absolute_url()
Entry.objects.filter(pub_date__range=(start_date - end_date))
44. To activate your models
class attributes
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get(**kwargs)
month
45. Lookup type that returns results that fall into an inclusive date range.
intermediate models
null
range
using(alias)
46. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
MultipleObjectsReturned
Proxy model
order_by(*fields)
ordered
47. 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.
istartswith
DoesNotExist
exact
~
48. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
49. Keyword shortcut for looking up an object by primary key.
dates(field - kind - order='ASC')
month
pk
Field lookups
50. This model method is used for updating a ManyToManyField.
ManyToManyField
add()
all()
distinct()