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. 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.
latest(field_name=None)
Meta class
default
iteration
2. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
one-to-one relationship
model
Q(question__istartswith='What')
help_text
3. These add custom "row-level" functionality to your objects. These act on a particular model instance.
lt
annotate(args - *kwargs)
only(*fields)
Custom model methods
4. If True - the table does not permit duplicate values for this field.
distinct()
unique
defer(*fields)
Restrictions on field names
5. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
~
intermediate models
delete()
null
6. The database that will be used if this query is executed now
db
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
==
Entry.objects.filter(pub_date__range=(start_date - end_date))
7. 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.
id field
Many-to-many relationship through an intermediate model
db
8. If this option is True - Django will store empty values as NULL in the database. Default is False.
class attributes
count()
null
filter chaining
9. 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
10. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
ordered
get(**kwargs)
get(**kwargs)
11. 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.
year
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
__unicode__()
primary_key
12. This model method saves a model instance to the database. This method has no return value.
select_related()
save()
Entry.objects.filter(pub_date__year=2005).delete()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
13. 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.
regex
blank
Abstract base class
search
14. 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
Many-to-many relationship through an intermediate model
clear() method
aggregate(args - *kwargs)
15. Lookup type that returns results less than a given value.
Entry.objects.filter(pub_date__year=2005).delete()
lt
iterator()
save()
16. 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.
id field
add()
Q()
Entry.objects.filter(id__gt=4)
17. This is a criterion that narrow down a QuerySet based on given parameters.
save()
filter
delete()
Q()
18. 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
exact
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
MultipleObjectsReturned
relationship spanning
19. Lookup type that returns results in a given list.
Meta class
in
Q()
distinct()
20. Manager method used to retrieve every object in a model.
all()
values(*fields)
Multi-table inheritance
clear() method
21. The default for this is the name of the child class followed by '_set'.
reverse name
regex
exists()
lt
22. Lookup type that finds a case-insensitive regular expression match.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
iregex
iexact
__unicode__()
23. 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
one-to-one relationship
Abstract base class
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
annotate(args - *kwargs)
24. 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.
Multi-table inheritance
class attributes
in_bulk(id_list)
iregex
25. 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
iterator()
lt
OneToOneField
save()
26. Lookup type for date/datetime fields that finds a 'day of the week' match.
regex
week_day
exclude(**kwargs)
Meta class
27. This field is added automatically - but this behavior can be overridden
id field
reverse()
startswith
get_or_create(**kwargs)
28. This query deletes all Entry objects with a pub_date year of 2005.
when you add new apps to INSTALLED_APPS
Restrictions on field names
null
Entry.objects.filter(pub_date__year=2005).delete()
29. Defines a many-to-one relationship. ou use it just like any other Field type: by including it as a class attribute of your model.
id field
ForeignKey
distinct()
when you add new apps to INSTALLED_APPS
30. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
distinct()
search
intermediate models
31. a QuerySet can be sliced - using Python's array-slicing syntax.
year
~
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
slicing
32. Exception raised by get(**kwargs) if more than one item matches the query.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Entry.objects.filter(pub_date__range=(start_date - end_date))
filter(**kwargs)
MultipleObjectsReturned
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
year
many-to-many relationship
week_day
F()
34. Disjunction operator for Q objects.
Entry.objects.filter(pub_date__year=2005).delete()
all()
|
range
35. 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
range
blank
exclude(**kwargs)
36. 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.
related_name
values(*fields)
pickling
Entry.objects.filter(id__in=[1 - 3 - 4])
37. Negation operator for Q objects.
~
OneToOneField
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
annotate(args - *kwargs)
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.
Many-to-many relationship through an intermediate model
Custom model methods
order_by(*fields)
when you add new apps to INSTALLED_APPS
39. 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
40. If True - this field is the primary key for the model.
primary_key
Proxy model
values(*fields)
count()
41. (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.
get_absolute_url()
none()
Restrictions on field names
create(**kwargs)
42. Exception raised by get(**kwargs) if no items match the query.
MultipleObjectsReturned
DoesNotExist
only(*fields)
many-to-one relationship
43. 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
filter(**kwargs)
values_list(*fields)
none()
when you add new apps to INSTALLED_APPS
44. Conjuntion operator for Q objects.
update(**kwargs)
Custom model methods
primary_key
&
45. 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
MultipleObjectsReturned
values(*fields)
range
only(*fields)
46. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
select_related()
Entry.objects.filter(pub_date__range=(start_date - end_date))
many-to-many relationship
Many-to-many relationship through an intermediate model
47. This represents a collection of objects from your database. It can have zero - one or many filters.
Field lookups
delete()
Q(question__istartswith='What')
QuerySet
48. 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.
none()
in_bulk(id_list)
Many-to-many relationship through an intermediate model
QuerySet
49. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
Entry.objects.filter(id__in=[1 - 3 - 4])
iendswith
values(*fields)
50. 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