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. 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.
choices
Model metadata
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
clear() method
2. 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
3. Lookup type that returns results less than a given value.
lt
Manager
filter chaining
regex
4. This field is added automatically - but this behavior can be overridden
id field
Entry.objects.filter(pub_date__year=2005).delete()
QuerySet
year
5. Lookup type that returns results that fall into an inclusive date range.
one-to-one relationship
annotate(args - *kwargs)
choices
range
6. 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
7. 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.
ordered
ForeignKey
get(**kwargs)
day
8. Negation operator for Q objects.
year
in
db
~
9. The default for this is the name of the child class followed by '_set'.
all()
reverse name
day
iregex
10. If True - this field is the primary key for the model.
__unicode__()
primary_key
Manager
help_text
11. 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.
Meta class
get(**kwargs)
order_by(*fields)
latest(field_name=None)
12. Disjunction operator for Q objects.
update()
|
many-to-many relationship
filter(**kwargs)
13. This gives your model metadata.
distinct()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Meta class
class attributes
14. 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
choices tuple
update()
id field
class type
15. 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
16. 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.
latest(field_name=None)
iexact
pickling
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
17. 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.
gte
reverse name
values_list(*fields)
iendswith
18. Conjuntion operator for Q objects.
Abstract base class
year
&
iteration
19. Lookup type that tests for inclusion in a case-sensitive fashion.
filter
class attributes
filter(**kwargs)
contains
20. This is a criterion that narrow down a QuerySet based on given parameters.
lte
only(*fields)
filter
iterator()
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.
OneToOneField
Q()
model
day
22. 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
ForeignKey
defer(*fields)
get_absolute_url()
through argument
23. (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.
DoesNotExist
delete()
Restrictions on field names
help_text
24. Returns the object matching the given lookup parameters
Proxy model
ordered
get(**kwargs)
Meta class
25. 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.
Restrictions on field names
Q()
get_absolute_url()
Q(question__istartswith='What')
26. A convenience method for constructing an object and saving it all in one step.
==
iterator()
create(**kwargs)
related_name
27. Exception raised by get(**kwargs) if no items match the query.
lte
none()
update(**kwargs)
DoesNotExist
28. 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.
class attributes
regex
month
Many-to-many relationship through an intermediate model
29. Lookup type that returns results less than or equal to a given value.
save()
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
lte
30. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
get_absolute_url()
null
filter(**kwargs)
regex
31. 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
32. This query deletes all Entry objects with a pub_date year of 2005.
Meta class
clear() method
Entry.objects.filter(pub_date__year=2005).delete()
Many-to-many relationship to self
33. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
get_absolute_url()
none()
related_name
Manager
34. 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)
Q()
save()
in
35. 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.
help_text
Model metadata
Abstract base class
ManyToManyField
36. 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.
Abstract base class
reverse()
get_absolute_url()
filter(**kwargs)
37. 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.
~
exact
values_list(*fields)
Many-to-many relationship through an intermediate model
38. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
range
==
Meta class
iexact
39. 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.
get_absolute_url()
select_related()
relationship spanning
Multi-table inheritance
40. Lookup type that returns results greater than or equal to a given value.
istartswith
__unicode__()
gte
choices tuple
41. 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
delete()
Many-to-many relationship through an intermediate model
exists()
ForeignKey
42. 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.
primary_key
delete()
update()
filter chaining
43. Fields are specified by these
annotate(args - *kwargs)
ManyToManyField
class attributes
Many-to-many relationship to self
44. Lookup type that returns results with a case-sensitive end sequence.
endswith
primary_key
unique
when you add new apps to INSTALLED_APPS
45. These methods are intended to do "table-wide" things.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
help_text
Manager methods
null
46. 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)
&
pk
Entry.objects.filter(pub_date__range=(start_date - end_date))
47. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
model
year
one-to-one relationship
filter(**kwargs)
48. Lookup type for date/datetime fields that finds an exact day match.
filter
intermediate models
range
day
49. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
filter(**kwargs)
year
Entry.objects.filter(id__gt=4)
50. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Entry.objects.filter(id__in=[1 - 3 - 4])
lte
filter(**kwargs)
get_or_create(**kwargs)