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. 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
2. Can be used to remove all many-to-many relationships for an instance
null
clear() method
regex
default
3. This query finds all entries between a start date of start_date and an end date of end_date.
only(*fields)
in_bulk(id_list)
Entry.objects.filter(pub_date__range=(start_date - end_date))
Many-to-many relationship through an intermediate model
4. 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
5. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
Many-to-many relationship through an intermediate model
&
F()
6. Lookup type that yields a case-insensitive match.
add()
Manager
iexact
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
7. 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
exists()
get_absolute_url()
intermediate models
update(**kwargs)
8. Lookup type that returns results less than or equal to a given value.
one-to-one relationship
lte
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Meta class
9. This query finds all entries with an id greater than 4.
defer(*fields)
Entry.objects.filter(id__gt=4)
null
unique
10. 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.
get(**kwargs)
select_related()
distinct()
Q()
11. Fields are specified by these
Entry.objects.filter(id__gt=4)
iregex
update(**kwargs)
class attributes
12. 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.
distinct()
choices tuple
in
isnull
13. 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
filter(**kwargs)
lte
get_or_create(**kwargs)
14. 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
15. 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.
get(**kwargs)
many-to-one relationship
all()
QuerySet
16. 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
only(*fields)
Proxy model
update(**kwargs)
none()
17. 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.
many-to-one relationship
none()
==
OneToOneField
18. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
regex
distinct()
isnull
19. 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.
id field
class attributes
Many-to-many relationship to self
iregex
20. 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
Abstract base class
evaluation
istartswith
21. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
distinct()
in
get_absolute_url()
22. This gives your model metadata.
get_or_create(**kwargs)
day
Meta class
pickling
23. Returns the most recent object in the table - by date - using the field_name provided as the date field.
exclude(**kwargs)
Q()
latest(field_name=None)
when you add new apps to INSTALLED_APPS
24. A convenience method for looking up an object with the given kwargs - creating one if necessary.
~
get(**kwargs)
get_or_create(**kwargs)
regex
25. Lookup type that returns results with a case-sensitive start sequence.
db
select_related()
get(**kwargs)
startswith
26. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
add()
regex
iteration
27. 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.
ManyToManyField
DoesNotExist
Manager
values_list(*fields)
28. Lookup type that returns results greater than a given value.
QuerySet
gt
iexact
gte
29. 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
exists()
through argument
add()
related_name
30. 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.
Multi-table inheritance
iteration
distinct()
update()
31. 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
32. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Abstract base class
save()
one-to-one relationship
related_name
33. Lookup type that returns results that fall into an inclusive date range.
filter
range
exclude(**kwargs)
model
34. This method immediately deletes the object and has no return value.
pk
clear() method
exact
delete()
35. 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.
add()
filter(**kwargs)
pickling
exact
36. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
Meta class
Many-to-many relationship through an intermediate model
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
37. 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
38. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
count()
filter chaining
values(*fields)
lt
39. Returns the object matching the given lookup parameters
Entry.objects.filter(id__gt=4)
Custom model methods
default
get(**kwargs)
40. When to run syncdb
Manager
when you add new apps to INSTALLED_APPS
many-to-many relationship
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
41. Lookup type that returns results with a case-insensitive start sequence.
choices tuple
istartswith
lte
week_day
42. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
Entry.objects.filter(id__gt=4)
in_bulk(id_list)
istartswith
43. The default for this is the name of the child class followed by '_set'.
related_name
day
reverse name
&
44. 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.
aggregate(args - *kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Custom model methods
range
45. Manager method used to retrieve every object in a model.
&
intermediate models
isnull
all()
46. This is a criterion that narrow down a QuerySet based on given parameters.
filter
get(**kwargs)
ManyToManyField
Entry.objects.filter(pub_date__year=2005).delete()
47. This represents a collection of objects from your database. It can have zero - one or many filters.
update()
Restrictions on field names
iendswith
QuerySet
48. 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()
aggregate(args - *kwargs)
evaluation
ordered
MultipleObjectsReturned
49. A convenience method for constructing an object and saving it all in one step.
choices
in
id field
create(**kwargs)
50. 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
Manager
through argument
~
annotate(args - *kwargs)