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. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
MultipleObjectsReturned
null
default
2. 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
3. This represents a collection of objects from your database. It can have zero - one or many filters.
exclude(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
QuerySet
Model metadata
4. 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.
update()
Custom model methods
Multi-table inheritance
delete()
5. 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.
default
only(*fields)
save()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
6. 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.
many-to-one relationship
|
blank
update()
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()
isnull
evaluation
__unicode__()
slicing
8. This gives your model metadata.
db
Meta class
&
distinct()
9. This query finds all entries with an id greater than 4.
iregex
Model metadata
Entry.objects.filter(id__gt=4)
__unicode__()
10. 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.
primary_key
ManyToManyField
Multi-table inheritance
Model metadata
11. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
gte
select_related()
Custom model methods
distinct()
12. Disjunction operator for Q objects.
values_list(*fields)
gt
|
regex
13. This query finds all entries with an id in the list [1 - 3 - 4]
get_absolute_url()
db
help_text
Entry.objects.filter(id__in=[1 - 3 - 4])
14. These methods are intended to do "table-wide" things.
==
Manager methods
contains
Entry.objects.filter(id__gt=4)
15. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
month
gte
choices
16. 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.
in_bulk(id_list)
get(**kwargs)
evaluation
add()
17. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
save()
year
model
one-to-one relationship
18. 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)
aggregate(args - *kwargs)
dates(field - kind - order='ASC')
19. 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
unique
get_absolute_url()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
20. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Manager
month
Model metadata
help_text
21. This query finds all entries between a start date of start_date and an end date of end_date.
Q(question__istartswith='What')
only(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
filter(**kwargs)
22. 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
startswith
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
filter(**kwargs)
23. Fields are specified by these
aggregate(args - *kwargs)
istartswith
class attributes
reverse name
24. This model method saves a model instance to the database. This method has no return value.
Manager methods
save()
iexact
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
25. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
defer(*fields)
intermediate models
distinct()
26. Lookup type that returns results less than a given value.
distinct()
startswith
dates(field - kind - order='ASC')
lt
27. Lookup type that yields a case-insensitive match.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Many-to-many relationship through an intermediate model
search
iexact
28. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
create(**kwargs)
ordered
pk
29. 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.
relationship spanning
exact
endswith
Many-to-many relationship to self
30. Returns the object matching the given lookup parameters
|
get(**kwargs)
save()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
31. 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
lt
endswith
Manager methods
32. Lookup type that returns results with a case-insensitive start sequence.
distinct()
add()
delete()
istartswith
33. 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.
model
get_absolute_url()
year
values_list(*fields)
34. Lookup type that finds a case-sensitive regular expression match.
regex
Manager methods
iteration
intermediate models
35. 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
&
F()
count()
range
36. 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.
__unicode__()
exact
Restrictions on field names
37. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
ordered
isnull
month
exact
38. 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.
filter(**kwargs)
gt
|
Q()
39. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
Proxy model
values_list(*fields)
values(*fields)
only(*fields)
40. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
~
get_or_create(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
41. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
get(**kwargs)
exclude(**kwargs)
Custom model methods
update()
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
reverse()
filter
none()
ManyToManyField
43. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
many-to-many relationship
defer(*fields)
Meta class
year
44. Lookup type that returns results with a case-sensitive start sequence.
unique
dates(field - kind - order='ASC')
Model metadata
startswith
45. 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
iteration
all()
annotate(args - *kwargs)
filter chaining
46. Exception raised by get(**kwargs) if no items match the query.
Field lookups
order_by(*fields)
DoesNotExist
distinct()
47. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
related_name
iterator()
filter(**kwargs)
48. This field is added automatically - but this behavior can be overridden
|
id field
select_related()
ordered
49. 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.
pk
reverse()
filter(**kwargs)
in_bulk(id_list)
50. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
get(**kwargs)
~
gte