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. Lookup type that returns results that fall into an inclusive date range.
range
reverse()
exclude(**kwargs)
lt
2. 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.
update()
gte
OneToOneField
unique
3. Fields are specified by these
class attributes
ForeignKey
values(*fields)
isnull
4. 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.
unique
aggregate(args - *kwargs)
filter(**kwargs)
relationship spanning
5. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
unique
month
iteration
many-to-one relationship
6. 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.
choices
istartswith
none()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
7. Manager method used to retrieve every object in a model.
select_related()
all()
iendswith
search
8. Exception raised by get(**kwargs) if more than one item matches the query.
iteration
filter(**kwargs)
MultipleObjectsReturned
istartswith
9. 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
10. 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.
pickling
update()
isnull
iteration
11. 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
12. To activate your models
__unicode__()
order_by(*fields)
startswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
13. Lookup type that returns results less than a given value.
lt
blank
filter(**kwargs)
intermediate models
14. Lookup type that returns results greater than a given value.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
choices tuple
gt
exclude(**kwargs)
15. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
slicing
F()
lte
16. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
lt
ordered
delete()
17. 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.
reverse name
none()
primary_key
using(alias)
18. 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
19. Lookup type that returns results in a given list.
many-to-one relationship
primary_key
in
null
20. 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
many-to-many relationship
__unicode__()
OneToOneField
update(**kwargs)
21. 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
22. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.
iterator()
when you add new apps to INSTALLED_APPS
regex
Many-to-many relationship to self
23. 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
reverse name
order_by(*fields)
get(**kwargs)
intermediate models
24. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
week_day
Entry.objects.filter(id__in=[1 - 3 - 4])
only(*fields)
25. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
==
year
count()
week_day
26. This model method is used for updating a ManyToManyField.
lt
null
add()
pickling
27. Exception raised by get(**kwargs) if no items match the query.
Manager methods
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_absolute_url()
DoesNotExist
28. Lookup type that tests for inclusion in a case-sensitive fashion.
exact
contains
through argument
update()
29. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
many-to-one relationship
order_by(*fields)
choices tuple
30. This field is added automatically - but this behavior can be overridden
id field
reverse()
in
exists()
31. A Python "magic method" that returns a unicode "representation" of any object.
search
__unicode__()
choices tuple
Custom model methods
32. Returns the object matching the given lookup parameters
get(**kwargs)
class type
~
db
33. 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)
Model metadata
none()
regex
dates(field - kind - order='ASC')
34. 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
OneToOneField
Abstract base class
one-to-one relationship
Custom model methods
35. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th
Manager
defer(*fields)
exists()
istartswith
36. Lookup type that returns results with a case-insensitive start sequence.
default
istartswith
order_by(*fields)
intermediate models
37. 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.
save()
__unicode__()
Many-to-many relationship through an intermediate model
order_by(*fields)
38. Negation operator for Q objects.
iterator()
using(alias)
&
~
39. The default for this is the name of the child class followed by '_set'.
get(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
reverse name
40. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
Restrictions on field names
~
update(**kwargs)
41. These methods are intended to do "table-wide" things.
istartswith
Manager methods
save()
filter chaining
42. 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
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
none()
intermediate models
values(*fields)
43. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
choices tuple
Custom model methods
id field
44. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
model
using(alias)
clear() method
get(**kwargs)
45. This is a criterion that narrow down a QuerySet based on given parameters.
endswith
startswith
search
filter
46. Returns a new QuerySet containing objects that match the given lookup parameters.
iterator()
__unicode__()
through argument
filter(**kwargs)
47. These add custom "row-level" functionality to your objects. These act on a particular model instance.
evaluation
when you add new apps to INSTALLED_APPS
Custom model methods
gte
48. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
filter(**kwargs)
ordered
istartswith
49. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.filter(id__in=[1 - 3 - 4])
exists()
search
50. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
distinct()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)