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. (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.
one-to-one relationship
filter(**kwargs)
Restrictions on field names
exists()
2. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
exists()
primary_key
count()
year
3. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
get(**kwargs)
gt
Many-to-many relationship to self
4. 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
Q()
annotate(args - *kwargs)
unique
class attributes
5. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
reverse name
iteration
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
defer(*fields)
6. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
Meta class
select_related()
many-to-many relationship
range
7. These methods are intended to do "table-wide" things.
exists()
Manager methods
get(**kwargs)
help_text
8. 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
select_related()
in_bulk(id_list)
get(**kwargs)
9. Lookup type that returns results that fall into an inclusive date range.
distinct()
Restrictions on field names
range
exists()
10. 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
Manager methods
intermediate models
defer(*fields)
class type
11. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
values_list(*fields)
filter(**kwargs)
model
12. 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
ManyToManyField
Multi-table inheritance
iteration
13. 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.
many-to-many relationship
delete()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
ForeignKey
14. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Custom model methods
iterator()
distinct()
in_bulk(id_list)
15. This represents a collection of objects from your database. It can have zero - one or many filters.
istartswith
QuerySet
add()
reverse()
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.
Q()
OneToOneField
default
endswith
17. Conjuntion operator for Q objects.
Abstract base class
get_absolute_url()
&
Entry.objects.filter(id__in=[1 - 3 - 4])
18. 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.
MultipleObjectsReturned
intermediate models
distinct()
using(alias)
19. Lookup type that returns results less than or equal to a given value.
contains
save()
lte
filter chaining
20. 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
ManyToManyField
none()
Custom model methods
search
21. 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
|
Abstract base class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
evaluation
22. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
endswith
db
year
get(**kwargs)
23. 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.
reverse name
db
OneToOneField
using(alias)
24. The database that will be used if this query is executed now
relationship spanning
db
Entry.objects.filter(pub_date__range=(start_date - end_date))
year
25. Lookup type that yields a case-insensitive match.
iexact
Meta class
model
day
26. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
__unicode__()
Field lookups
ForeignKey
ordered
27. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
get(**kwargs)
all()
month
iregex
28. 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
29. 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
Many-to-many relationship through an intermediate model
range
relationship spanning
through argument
30. 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.
year
order_by(*fields)
endswith
istartswith
31. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Abstract base class
intermediate models
count()
Field lookups
32. A convenience method for constructing an object and saving it all in one step.
class attributes
create(**kwargs)
none()
Model metadata
33. 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.
count()
relationship spanning
clear() method
ForeignKey
34. Lookup type that returns results greater than a given value.
MultipleObjectsReturned
Manager
gt
related_name
35. 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
36. Disjunction operator for Q objects.
|
dates(field - kind - order='ASC')
iterator()
filter chaining
37. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
==
all()
exclude(**kwargs)
Q()
38. This field is added automatically - but this behavior can be overridden
exists()
id field
only(*fields)
model
39. 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
Q(question__istartswith='What')
iterator()
Multi-table inheritance
&
40. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
intermediate models
related_name
Custom model methods
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
41. Returns a new QuerySet containing objects that match the given lookup parameters.
pk
filter(**kwargs)
many-to-one relationship
filter
42. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
exclude(**kwargs)
filter chaining
delete()
isnull
43. The default for this is the name of the child class followed by '_set'.
__unicode__()
reverse name
filter(**kwargs)
Restrictions on field names
44. If this option is True - Django will store empty values as NULL in the database. Default is False.
get_or_create(**kwargs)
exists()
Multi-table inheritance
null
45. This model method is used for updating a ManyToManyField.
when you add new apps to INSTALLED_APPS
add()
Custom model methods
month
46. 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
lt
|
startswith
Proxy model
47. 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
48. 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.
Model metadata
Entry.objects.filter(id__in=[1 - 3 - 4])
create(**kwargs)
exact
49. Lookup type that finds a case-sensitive regular expression match.
isnull
pickling
regex
Q(question__istartswith='What')
50. Lookup type that returns results greater than or equal to a given value.
gte
MultipleObjectsReturned
~
db