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. 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.
db
many-to-one relationship
iendswith
Entry.objects.filter(id__in=[1 - 3 - 4])
2. Can be used to remove all many-to-many relationships for an instance
gt
clear() method
filter(**kwargs)
related_name
3. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
iterator()
exclude(**kwargs)
==
ManyToManyField
4. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
intermediate models
aggregate(args - *kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
5. 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.
filter chaining
iregex
choices
__unicode__()
6. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
iterator()
latest(field_name=None)
Q(question__istartswith='What')
7. Keyword shortcut for looking up an object by primary key.
lt
filter(**kwargs)
Entry.objects.filter(id__gt=4)
pk
8. Lookup type that returns results that fall into an inclusive date range.
~
through argument
Entry.objects.filter(pub_date__range=(start_date - end_date))
range
9. 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.
ForeignKey
create(**kwargs)
choices tuple
Entry.objects.filter(id__gt=4)
10. Lookup type for date/datetime fields that finds an exact day match.
ForeignKey
latest(field_name=None)
day
distinct()
11. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
month
values(*fields)
Custom model methods
Many-to-many relationship through an intermediate model
12. 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
13. If True - the table does not permit duplicate values for this field.
ordered
unique
year
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
14. Lookup type that returns results in a given list.
in
iexact
class type
exclude(**kwargs)
15. 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
Many-to-many relationship through an intermediate model
clear() method
annotate(args - *kwargs)
lte
16. 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
Manager methods
iteration
relationship spanning
update()
17. 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.
ordered
pickling
aggregate(args - *kwargs)
iteration
18. 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()
count()
in
evaluation
many-to-one relationship
19. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
OneToOneField
isnull
Field lookups
model
20. This query deletes all Entry objects with a pub_date year of 2005.
Many-to-many relationship to self
Entry.objects.filter(pub_date__year=2005).delete()
values_list(*fields)
class attributes
21. 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
filter(**kwargs)
only(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
gt
22. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
Entry.objects.filter(pub_date__range=(start_date - end_date))
Q()
get(**kwargs)
23. Conjuntion operator for Q objects.
&
one-to-one relationship
~
update(**kwargs)
24. (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.
slicing
Restrictions on field names
delete()
model
25. Lookup type that tests for inclusion in a case-sensitive fashion.
Field lookups
contains
search
filter(**kwargs)
26. 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.
model
help_text
Entry.objects.filter(pub_date__year=2005).delete()
27. 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.
delete()
in_bulk(id_list)
MultipleObjectsReturned
day
28. 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.
Q(question__istartswith='What')
|
default
help_text
29. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
in_bulk(id_list)
lt
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
related_name
30. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
week_day
Field lookups
endswith
iteration
31. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
db
Model metadata
ManyToManyField
32. 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.
delete()
get(**kwargs)
exists()
update()
33. 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
through argument
Entry.objects.filter(pub_date__year=2005).delete()
Proxy model
delete()
34. Lookup type that returns results less than or equal to a given value.
istartswith
lte
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Entry.objects.filter(id__in=[1 - 3 - 4])
35. Fields are specified by these
class attributes
help_text
Q(question__istartswith='What')
values(*fields)
36. 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
Proxy model
class type
==
choices tuple
37. The default for this is the name of the child class followed by '_set'.
reverse name
~
many-to-many relationship
month
38. Disjunction operator for Q objects.
delete()
|
Entry.objects.filter(pub_date__range=(start_date - end_date))
iregex
39. Lookup type that returns results with a case-insensitive end sequence.
ordered
Model metadata
Manager methods
iendswith
40. These methods are intended to do "table-wide" things.
Manager methods
unique
Q()
relationship spanning
41. 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.
count()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)
exclude(**kwargs)
42. Lookup type that finds a case-sensitive regular expression match.
all()
using(alias)
help_text
regex
43. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
null
get_or_create(**kwargs)
Q()
month
44. 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
aggregate(args - *kwargs)
none()
MultipleObjectsReturned
Q()
45. This field is added automatically - but this behavior can be overridden
choices tuple
id field
exact
==
46. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
exclude(**kwargs)
Model metadata
get(**kwargs)
47. 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.
Manager
filter(**kwargs)
search
Q(question__istartswith='What')
48. 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.
order_by(*fields)
Many-to-many relationship through an intermediate model
all()
Abstract base class
49. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
intermediate models
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
relationship spanning
50. 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
all()
iexact
values_list(*fields)
blank