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. Keyword shortcut for looking up an object by primary key.
&
__unicode__()
pk
Restrictions on field names
2. Lookup type that returns results that fall into an inclusive date range.
reverse name
range
Q(question__istartswith='What')
get(**kwargs)
3. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
pk
filter
intermediate models
one-to-one relationship
4. 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.
Many-to-many relationship to self
in_bulk(id_list)
reverse()
update(**kwargs)
5. To activate your models
clear() method
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
filter(**kwargs)
6. 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.
delete()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
ManyToManyField
create(**kwargs)
7. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
Meta class
distinct()
dates(field - kind - order='ASC')
8. If this option is True - the field is allowed to be blank. Default is False.
endswith
update()
blank
related_name
9. Exception raised by get(**kwargs) if no items match the query.
related_name
contains
DoesNotExist
evaluation
10. Used to get a QuerySet for a model. This is called 'objects' by default.
default
Manager
isnull
Many-to-many relationship to self
11. 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.
none()
get_or_create(**kwargs)
contains
update()
12. 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.
model
Many-to-many relationship through an intermediate model
OneToOneField
contains
13. 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
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
&
Q()
14. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
annotate(args - *kwargs)
Custom model methods
MultipleObjectsReturned
==
15. Lookup type that tests for inclusion in a case-sensitive fashion.
all()
annotate(args - *kwargs)
contains
exists()
16. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
filter chaining
when you add new apps to INSTALLED_APPS
pickling
default
17. Disjunction operator for Q objects.
|
get_absolute_url()
iexact
~
18. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
using(alias)
create(**kwargs)
Custom model methods
19. 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
class type
OneToOneField
iexact
add()
20. 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.
choices
class attributes
values_list(*fields)
aggregate(args - *kwargs)
21. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
annotate(args - *kwargs)
many-to-many relationship
22. These add custom "row-level" functionality to your objects. These act on a particular model instance.
through argument
Entry.objects.filter(id__gt=4)
Q()
Custom model methods
23. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
none()
defer(*fields)
filter
24. Lookup type that returns results with a case-insensitive end sequence.
day
iendswith
&
week_day
25. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
ForeignKey
contains
values(*fields)
one-to-one relationship
26. This field is added automatically - but this behavior can be overridden
id field
aggregate(args - *kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
primary_key
27. 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()
get_or_create(**kwargs)
regex
create(**kwargs)
28. Negation operator for Q objects.
~
slicing
search
Meta class
29. Lookup type for date/datetime fields that finds an exact day match.
using(alias)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Meta class
day
30. 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.
count()
in_bulk(id_list)
Many-to-many relationship to self
Entry.objects.filter(pub_date__year=2005).delete()
31. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Q(question__istartswith='What')
exclude(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
Many-to-many relationship through an intermediate model
32. 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.
distinct()
in
get(**kwargs)
OneToOneField
33. 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.
34. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
add()
intermediate models
get(**kwargs)
35. 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
many-to-one relationship
Entry.objects.filter(id__gt=4)
filter chaining
iterator()
36. The database that will be used if this query is executed now
db
exclude(**kwargs)
isnull
filter(**kwargs)
37. Can be used to remove all many-to-many relationships for an instance
delete()
delete()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
clear() method
38. If this option is True - Django will store empty values as NULL in the database. Default is False.
Abstract base class
model
null
filter
39. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
40. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
QuerySet
count()
Model metadata
Q()
41. This is a criterion that narrow down a QuerySet based on given parameters.
filter
regex
get_or_create(**kwargs)
slicing
42. 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
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
in
exists()
annotate(args - *kwargs)
43. Lookup type that returns results greater than a given value.
annotate(args - *kwargs)
lt
iterator()
gt
44. 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.
__unicode__()
choices
gte
related_name
45. 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.
gte
Q()
annotate(args - *kwargs)
many-to-one relationship
46. When to run syncdb
count()
when you add new apps to INSTALLED_APPS
get_absolute_url()
dates(field - kind - order='ASC')
47. Lookup type that returns results in a given list.
day
add()
in
==
48. Lookup type that returns results greater than or equal to a given value.
reverse name
ForeignKey
gte
get_or_create(**kwargs)
49. Lookup type that returns results less than a given value.
all()
class type
search
lt
50. 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)
relationship spanning
primary_key
Many-to-many relationship to self
Model metadata