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. 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
ManyToManyField
lte
update(**kwargs)
Model metadata
2. (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.
Restrictions on field names
class attributes
&
ForeignKey
3. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
values_list(*fields)
week_day
Restrictions on field names
4. 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.
add()
choices
filter chaining
id field
5. 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.
endswith
aggregate(args - *kwargs)
ordered
choices tuple
6. 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
get(**kwargs)
annotate(args - *kwargs)
help_text
only(*fields)
7. 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
clear() method
class type
help_text
many-to-one relationship
8. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
delete()
order_by(*fields)
iregex
==
9. Lookup type that returns results in a given list.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in
using(alias)
ordered
10. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
filter(**kwargs)
exact
Entry.objects.filter(id__in=[1 - 3 - 4])
11. Lookup type that returns results that fall into an inclusive date range.
day
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
range
12. Defines a one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.filter(id__gt=4)
OneToOneField
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
filter
13. 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
14. Conjuntion operator for Q objects.
search
istartswith
&
Many-to-many relationship through an intermediate model
15. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
range
in
month
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
16. Lookup type that returns results greater than a given value.
search
gt
through argument
exists()
17. Lookup type that returns results less than or equal to a given value.
==
ordered
lte
null
18. To activate your models
iteration
values_list(*fields)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
update(**kwargs)
19. If this option is True - the field is allowed to be blank. Default is False.
filter chaining
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
blank
|
20. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
class type
startswith
21. 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
unique
all()
delete()
get_absolute_url()
22. 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
lte
Field lookups
Many-to-many relationship through an intermediate model
23. 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.
choices
delete()
regex
aggregate(args - *kwargs)
24. Lookup type that finds a case-sensitive regular expression match.
regex
delete()
filter
OneToOneField
25. These methods are intended to do "table-wide" things.
many-to-many relationship
order_by(*fields)
regex
Manager methods
26. Lookup type that finds a case-insensitive regular expression match.
gt
delete()
pk
iregex
27. Lookup type that returns results with a case-sensitive end sequence.
get(**kwargs)
when you add new apps to INSTALLED_APPS
endswith
iregex
28. Lookup type that yields a case-insensitive match.
iexact
values_list(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
29. Exception raised by get(**kwargs) if no items match the query.
all()
isnull
DoesNotExist
relationship spanning
30. 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.
values_list(*fields)
gt
blank
in_bulk(id_list)
31. 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.
when you add new apps to INSTALLED_APPS
ForeignKey
blank
intermediate models
32. Lookup type that returns results with a case-insensitive start sequence.
istartswith
lt
filter chaining
one-to-one relationship
33. 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
intermediate models
all()
week_day
reverse()
34. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
Manager
==
DoesNotExist
35. 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
36. 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.
endswith
filter chaining
values(*fields)
in_bulk(id_list)
37. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
reverse()
annotate(args - *kwargs)
order_by(*fields)
38. 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()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Abstract base class
evaluation
gte
39. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
db
defer(*fields)
related_name
filter(**kwargs)
40. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
~
Custom model methods
iexact
41. 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
42. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
null
distinct()
count()
evaluation
43. This model method is used for updating a ManyToManyField.
DoesNotExist
add()
latest(field_name=None)
id field
44. If True - the table does not permit duplicate values for this field.
through argument
Entry.objects.filter(pub_date__year=2005).delete()
aggregate(args - *kwargs)
unique
45. 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.
distinct()
get_or_create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Q()
46. Disjunction operator for Q objects.
values_list(*fields)
istartswith
|
__unicode__()
47. 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.
reverse()
ManyToManyField
iendswith
&
48. This is a criterion that narrow down a QuerySet based on given parameters.
Manager methods
Restrictions on field names
filter
year
49. The database that will be used if this query is executed now
==
__unicode__()
iregex
db
50. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
all()
choices tuple
related_name
one-to-one relationship