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. 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.
Field lookups
choices tuple
search
values(*fields)
2. Fields are specified by these
month
exclude(**kwargs)
class attributes
gt
3. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
many-to-many relationship
MultipleObjectsReturned
Model metadata
4. This is a criterion that narrow down a QuerySet based on given parameters.
filter
in_bulk(id_list)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
5. 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
filter
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
only(*fields)
regex
6. 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
count()
through argument
__unicode__()
dates(field - kind - order='ASC')
7. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
in
Meta class
F()
8. Lookup type that tests for inclusion in a case-sensitive fashion.
id field
iexact
contains
Manager methods
9. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
clear() method
isnull
get(**kwargs)
exclude(**kwargs)
10. 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
11. 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
12. Keyword shortcut for looking up an object by primary key.
pk
Entry.objects.filter(id__gt=4)
Q()
delete()
13. 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.
QuerySet
pk
reverse()
id field
14. 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
15. Returns the most recent object in the table - by date - using the field_name provided as the date field.
primary_key
latest(field_name=None)
relationship spanning
iregex
16. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
update(**kwargs)
latest(field_name=None)
distinct()
all()
17. Lookup type that returns results with a case-insensitive start sequence.
through argument
istartswith
startswith
related_name
18. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
latest(field_name=None)
Meta class
unique
help_text
19. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
db
search
id field
20. This field is added automatically - but this behavior can be overridden
id field
relationship spanning
DoesNotExist
Custom model methods
21. Conjuntion operator for Q objects.
class attributes
iteration
&
blank
22. 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
relationship spanning
startswith
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
23. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
choices tuple
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get_or_create(**kwargs)
many-to-many relationship
24. 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.
==
Field lookups
exact
update(**kwargs)
25. Lookup type that returns results in a given list.
choices tuple
filter(**kwargs)
in
get(**kwargs)
26. 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.
filter chaining
count()
only(*fields)
contains
27. 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.
all()
contains
using(alias)
get(**kwargs)
28. Used to get a QuerySet for a model. This is called 'objects' by default.
search
Manager
regex
iregex
29. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
ordered
unique
search
month
30. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
class type
null
none()
31. A convenience method for constructing an object and saving it all in one step.
iteration
class type
create(**kwargs)
__unicode__()
32. This gives your model metadata.
__unicode__()
Meta class
primary_key
Entry.objects.filter(id__gt=4)
33. To activate your models
unique
Q(question__istartswith='What')
lt
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
34. These add custom "row-level" functionality to your objects. These act on a particular model instance.
one-to-one relationship
clear() method
model
Custom model methods
35. 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()
delete()
get(**kwargs)
36. Negation operator for Q objects.
update(**kwargs)
filter(**kwargs)
values(*fields)
~
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.
Field lookups
Q(question__istartswith='What')
Many-to-many relationship through an intermediate model
filter(**kwargs)
38. This query finds all entries between a start date of start_date and an end date of end_date.
db
Many-to-many relationship through an intermediate model
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
39. Can be used to remove all many-to-many relationships for an instance
clear() method
==
Restrictions on field names
istartswith
40. If this option is True - the field is allowed to be blank. Default is False.
relationship spanning
filter
blank
clear() method
41. This represents a collection of objects from your database. It can have zero - one or many filters.
F()
annotate(args - *kwargs)
QuerySet
related_name
42. Lookup type that returns results with a case-insensitive end sequence.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
filter(**kwargs)
count()
iendswith
43. 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.
using(alias)
in_bulk(id_list)
db
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
44. 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.
MultipleObjectsReturned
F()
class attributes
Many-to-many relationship to self
45. 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
46. If you pickle a QuerySet - this will force all the results to be loaded into memory prior to pickling. When you unpickle a QuerySet - it contains the results at the moment it was pickled - rather than the results that are currently in the database.
get(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
get_absolute_url()
pickling
47. 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.
Proxy model
iterator()
update()
delete()
48. 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.
using(alias)
Custom model methods
in
MultipleObjectsReturned
49. 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.
|
month
aggregate(args - *kwargs)
DoesNotExist
50. 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.
ordered
evaluation
pk
many-to-one relationship