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. 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
all()
values_list(*fields)
update(**kwargs)
through argument
2. 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
3. If True - this field is the primary key for the model.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
ManyToManyField
update(**kwargs)
primary_key
4. This field is added automatically - but this behavior can be overridden
slicing
evaluation
help_text
id field
5. Keyword shortcut for looking up an object by primary key.
filter(**kwargs)
istartswith
pk
class attributes
6. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
search
id field
Manager methods
7. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
search
month
Abstract base class
F()
8. 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
none()
distinct()
__unicode__()
reverse()
9. This query finds all entries with an id greater than 4.
pk
latest(field_name=None)
intermediate models
Entry.objects.filter(id__gt=4)
10. 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.
none()
ForeignKey
istartswith
slicing
11. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
defer(*fields)
choices
update()
12. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
filter(**kwargs)
reverse()
in
count()
13. 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
14. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
unique
choices tuple
Q(question__istartswith='What')
ordered
15. (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.
distinct()
filter(**kwargs)
evaluation
Restrictions on field names
16. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
&
QuerySet
related_name
exact
17. Lookup type that returns results with a case-insensitive end sequence.
model
iendswith
relationship spanning
in
18. Exception raised by get(**kwargs) if no items match the query.
ManyToManyField
Entry.objects.filter(id__in=[1 - 3 - 4])
lt
DoesNotExist
19. Lookup type that finds a case-sensitive regular expression match.
regex
exists()
&
default
20. 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
iregex
F()
ordered
isnull
21. Disjunction operator for Q objects.
|
endswith
id field
ForeignKey
22. The default for this is the name of the child class followed by '_set'.
choices tuple
reverse name
class type
class attributes
23. 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
==
MultipleObjectsReturned
in_bulk(id_list)
Proxy model
24. Lookup type that returns results that fall into an inclusive date range.
get(**kwargs)
Many-to-many relationship to self
add()
range
25. 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.
iterator()
Entry.objects.filter(pub_date__year=2005).delete()
choices tuple
range
26. 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
exact
intermediate models
==
lt
27. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
__unicode__()
filter
Field lookups
model
28. 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
29. 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
update(**kwargs)
annotate(args - *kwargs)
iendswith
only(*fields)
30. 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.
select_related()
blank
search
get(**kwargs)
31. Defines a many-to-many relationship. You use it just like any other Field type: by including it as a class attribute of your model.
annotate(args - *kwargs)
ManyToManyField
|
many-to-many relationship
32. When to run syncdb
when you add new apps to INSTALLED_APPS
update()
Restrictions on field names
related_name
33. 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.
Many-to-many relationship through an intermediate model
unique
get(**kwargs)
F()
34. 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
35. 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.
help_text
delete()
istartswith
choices
36. These methods are intended to do "table-wide" things.
Many-to-many relationship to self
Proxy model
select_related()
Manager methods
37. 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.
update()
many-to-many relationship
filter chaining
reverse name
38. Lookup type that yields a case-insensitive match.
gt
help_text
unique
iexact
39. This method immediately deletes the object and has no return value.
delete()
Model metadata
in_bulk(id_list)
==
40. 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.
order_by(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
range
month
41. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
DoesNotExist
filter(**kwargs)
Field lookups
reverse name
42. Lookup type that returns results with a case-insensitive start sequence.
contains
istartswith
filter chaining
class type
43. If True - the table does not permit duplicate values for this field.
Entry.objects.filter(pub_date__year=2005).delete()
in_bulk(id_list)
delete()
unique
44. 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.
pickling
distinct()
many-to-many relationship
Many-to-many relationship through an intermediate model
45. A Python "magic method" that returns a unicode "representation" of any object.
Many-to-many relationship through an intermediate model
contains
__unicode__()
month
46. Exception raised by get(**kwargs) if more than one item matches the query.
Manager methods
&
MultipleObjectsReturned
select_related()
47. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
month
search
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
isnull
48. This query finds all entries with an id in the list [1 - 3 - 4]
regex
Entry.objects.filter(id__in=[1 - 3 - 4])
week_day
all()
49. 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
one-to-one relationship
relationship spanning
select_related()
null
50. Lookup type that returns results greater than or equal to a given value.
gte
get_or_create(**kwargs)
ForeignKey
in_bulk(id_list)