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. 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.
get(**kwargs)
get_absolute_url()
aggregate(args - *kwargs)
blank
2. 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.
iterator()
range
Meta class
pickling
3. This query finds all entries between a start date of start_date and an end date of end_date.
annotate(args - *kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
iteration
evaluation
4. 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.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
iterator()
primary_key
filter chaining
5. 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.
istartswith
clear() method
Entry.objects.filter(id__in=[1 - 3 - 4])
search
6. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
order_by(*fields)
model
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
all()
7. Lookup type that finds a case-insensitive regular expression match.
endswith
iregex
Field lookups
model
8. 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
db
clear() method
through argument
Entry.objects.filter(id__in=[1 - 3 - 4])
9. These add custom "row-level" functionality to your objects. These act on a particular model instance.
istartswith
intermediate models
Custom model methods
endswith
10. Disjunction operator for Q objects.
blank
iendswith
|
delete()
11. 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
null
annotate(args - *kwargs)
update(**kwargs)
when you add new apps to INSTALLED_APPS
12. 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.
iterator()
exists()
db
many-to-one relationship
13. Fields are specified by these
iregex
filter chaining
get(**kwargs)
class attributes
14. Lookup type that returns results less than or equal to a given value.
lte
day
blank
delete()
15. 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.
id field
help_text
F()
delete()
16. 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.
ForeignKey
many-to-one relationship
only(*fields)
__unicode__()
17. A Python "magic method" that returns a unicode "representation" of any object.
default
help_text
order_by(*fields)
__unicode__()
18. 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
id field
primary_key
Entry.objects.filter(id__gt=4)
19. 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
defer(*fields)
__unicode__()
endswith
dates(field - kind - order='ASC')
20. Lookup type that returns results in a given list.
Entry.objects.filter(id__gt=4)
iendswith
in
null
21. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
annotate(args - *kwargs)
all()
Multi-table inheritance
exists()
22. This represents a collection of objects from your database. It can have zero - one or many filters.
exact
count()
QuerySet
related_name
23. This field is added automatically - but this behavior can be overridden
id field
Custom model methods
endswith
add()
24. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.
class type
DoesNotExist
reverse()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
25. Lookup type that returns results less than a given value.
reverse name
many-to-one relationship
lt
default
26. This is a criterion that narrow down a QuerySet based on given parameters.
help_text
ordered
filter
month
27. This model method is used for updating a ManyToManyField.
evaluation
Entry.objects.filter(id__in=[1 - 3 - 4])
day
add()
28. 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
regex
in
Custom model methods
only(*fields)
29. 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
get_absolute_url()
dates(field - kind - order='ASC')
exists()
lt
30. 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.
DoesNotExist
relationship spanning
exact
update()
31. Lookup type that finds a case-sensitive regular expression match.
iteration
search
regex
help_text
32. 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-many relationship to self
iterator()
order_by(*fields)
Meta class
33. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
choices tuple
using(alias)
values(*fields)
unique
34. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
35. Exception raised by get(**kwargs) if no items match the query.
search
ForeignKey
month
DoesNotExist
36. When to run syncdb
reverse()
intermediate models
many-to-many relationship
when you add new apps to INSTALLED_APPS
37. 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
Proxy model
delete()
none()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
38. 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
create(**kwargs)
many-to-many relationship
intermediate models
update(**kwargs)
39. 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.
__unicode__()
delete()
intermediate models
Q()
40. This query deletes all Entry objects with a pub_date year of 2005.
clear() method
slicing
Entry.objects.filter(pub_date__year=2005).delete()
regex
41. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
through argument
filter(**kwargs)
class type
exact
42. 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
distinct()
values(*fields)
reverse()
43. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
annotate(args - *kwargs)
F()
ordered
Q(question__istartswith='What')
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.
Many-to-many relationship to self
ManyToManyField
choices tuple
ordered
45. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
exclude(**kwargs)
__unicode__()
id field
46. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode
Abstract base class
Many-to-many relationship to self
ManyToManyField
startswith
47. 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.
Manager methods
get_or_create(**kwargs)
delete()
48. If True - this field is the primary key for the model.
dates(field - kind - order='ASC')
exact
primary_key
Model metadata
49. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iexact
iteration
regex
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
50. A convenience method for constructing an object and saving it all in one step.
Restrictions on field names
unique
create(**kwargs)
~