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 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.
search
only(*fields)
update()
dates(field - kind - order='ASC')
2. This represents a collection of objects from your database. It can have zero - one or many filters.
iexact
__unicode__()
QuerySet
clear() method
3. 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
intermediate models
distinct()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
none()
4. Keyword shortcut for looking up an object by primary key.
regex
dates(field - kind - order='ASC')
Entry.objects.filter(pub_date__range=(start_date - end_date))
pk
5. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
intermediate models
filter(**kwargs)
get_or_create(**kwargs)
select_related()
6. 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.
default
MultipleObjectsReturned
reverse()
filter(**kwargs)
7. 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
QuerySet
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
none()
8. 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.
update(**kwargs)
Many-to-many relationship to self
filter(**kwargs)
lt
9. a QuerySet can be sliced - using Python's array-slicing syntax.
create(**kwargs)
slicing
search
intermediate models
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.
11. If True - this field is the primary key for the model.
default
istartswith
primary_key
iteration
12. Lookup type that finds a case-sensitive regular expression match.
Entry.objects.filter(id__in=[1 - 3 - 4])
regex
endswith
pickling
13. Lookup type that returns results less than or equal to a given value.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
lte
add()
istartswith
14. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
evaluation
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
month
delete()
15. Lookup type for date/datetime fields that finds an exact day match.
filter(**kwargs)
day
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
pk
16. These methods are intended to do "table-wide" things.
Manager methods
values_list(*fields)
Many-to-many relationship to self
help_text
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.
OneToOneField
lte
ManyToManyField
Custom model methods
18. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Entry.objects.filter(id__gt=4)
DoesNotExist
==
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
19. Exception raised by get(**kwargs) if no items match the query.
when you add new apps to INSTALLED_APPS
choices
day
DoesNotExist
20. If True - the table does not permit duplicate values for this field.
range
ordered
unique
select_related()
21. Used to get a QuerySet for a model. This is called 'objects' by default.
~
null
Manager
through argument
22. Lookup type that returns results greater than a given value.
ordered
count()
gt
iexact
23. Negation operator for Q objects.
ForeignKey
get_or_create(**kwargs)
~
class attributes
24. When to run syncdb
latest(field_name=None)
when you add new apps to INSTALLED_APPS
choices
contains
25. 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.
gt
endswith
ForeignKey
choices tuple
26. These add custom "row-level" functionality to your objects. These act on a particular model instance.
iregex
MultipleObjectsReturned
~
Custom model methods
27. Lookup type for date/datetime fields that finds a 'day of the week' match.
latest(field_name=None)
intermediate models
iregex
week_day
28. Lookup type that returns results with a case-sensitive start sequence.
distinct()
startswith
add()
exists()
29. 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.
Manager
Multi-table inheritance
gte
Many-to-many relationship through an intermediate model
30. Lookup type that yields a case-insensitive match.
pickling
only(*fields)
iexact
choices tuple
31. 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)
Restrictions on field names
Entry.objects.filter(id__gt=4)
MultipleObjectsReturned
32. 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
related_name
exists()
choices
class attributes
33. Lookup type that returns results less than a given value.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
week_day
lt
dates(field - kind - order='ASC')
34. The default for this is the name of the child class followed by '_set'.
Entry.objects.filter(pub_date__range=(start_date - end_date))
exists()
reverse name
many-to-one relationship
35. 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.
__unicode__()
related_name
in_bulk(id_list)
Abstract base class
36. 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.
in_bulk(id_list)
filter chaining
when you add new apps to INSTALLED_APPS
choices tuple
37. 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.
38. 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
iendswith
F()
year
search
39. Disjunction operator for Q objects.
get_or_create(**kwargs)
ordered
|
choices
40. 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
db
Entry.objects.filter(id__in=[1 - 3 - 4])
range
41. This field is added automatically - but this behavior can be overridden
iteration
id field
only(*fields)
endswith
42. The database that will be used if this query is executed now
unique
one-to-one relationship
save()
db
43. Lookup type that returns results that fall into an inclusive date range.
filter chaining
range
iregex
many-to-one relationship
44. 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()
Q(question__istartswith='What')
dates(field - kind - order='ASC')
iteration
evaluation
45. Exception raised by get(**kwargs) if more than one item matches the query.
distinct()
MultipleObjectsReturned
get(**kwargs)
many-to-one relationship
46. 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
defer(*fields)
==
pk
Proxy model
47. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
iterator()
in_bulk(id_list)
evaluation
48. Lookup type that returns results with a case-insensitive start sequence.
distinct()
istartswith
search
primary_key
49. Lookup type that finds a case-insensitive regular expression match.
iregex
save()
values(*fields)
exact
50. This query finds all entries with an id greater than 4.
relationship spanning
iregex
Entry.objects.filter(id__gt=4)
ordered