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 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
2. 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
one-to-one relationship
Abstract base class
QuerySet
intermediate models
3. 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
Entry.objects.filter(pub_date__year=2005).delete()
annotate(args - *kwargs)
in
Manager
4. Conjuntion operator for Q objects.
search
istartswith
&
iexact
5. Used to get a QuerySet for a model. This is called 'objects' by default.
__unicode__()
|
null
Manager
6. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
month
DoesNotExist
|
7. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
startswith
many-to-one relationship
pk
year
8. Lookup type that returns results with a case-sensitive end sequence.
create(**kwargs)
slicing
endswith
ForeignKey
9. (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.
class type
Restrictions on field names
Field lookups
one-to-one relationship
10. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
ManyToManyField
slicing
class type
11. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
help_text
exclude(**kwargs)
none()
Field lookups
12. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iendswith
search
many-to-many relationship
get(**kwargs)
13. 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.
isnull
search
exists()
pickling
14. 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.
in_bulk(id_list)
exists()
pk
in
15. If True - the table does not permit duplicate values for this field.
none()
unique
many-to-one relationship
many-to-many relationship
16. 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.
values_list(*fields)
iteration
reverse()
iendswith
17. When to run syncdb
pickling
Manager
when you add new apps to INSTALLED_APPS
filter(**kwargs)
18. Exception raised by get(**kwargs) if no items match the query.
ForeignKey
save()
search
DoesNotExist
19. 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
20. 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
get_absolute_url()
defer(*fields)
in_bulk(id_list)
endswith
21. The database that will be used if this query is executed now
ordered
dates(field - kind - order='ASC')
contains
db
22. Lookup type that yields a case-insensitive match.
iexact
gt
id field
using(alias)
23. 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.
values_list(*fields)
clear() method
order_by(*fields)
Model metadata
24. 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
gt
order_by(*fields)
update()
update(**kwargs)
25. 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()
all()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
latest(field_name=None)
evaluation
26. Lookup type for date/datetime fields that finds an exact day match.
~
day
Q()
reverse()
27. 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
Q()
none()
class type
iendswith
28. 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()
using(alias)
through argument
~
29. 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.
ordered
default
filter(**kwargs)
update(**kwargs)
30. A convenience method for constructing an object and saving it all in one step.
day
related_name
select_related()
create(**kwargs)
31. Returns the most recent object in the table - by date - using the field_name provided as the date field.
contains
save()
latest(field_name=None)
filter(**kwargs)
32. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
Custom model methods
Entry.objects.filter(id__in=[1 - 3 - 4])
pickling
33. 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.
Custom model methods
F()
aggregate(args - *kwargs)
istartswith
34. Lookup type that returns results less than a given value.
iregex
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in
lt
35. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
MultipleObjectsReturned
in
OneToOneField
delete()
36. Lookup type that returns results greater than a given value.
gt
filter(**kwargs)
delete()
week_day
37. 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
38. 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
select_related()
range
ordered
lt
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.
in
__unicode__()
evaluation
Q()
40. a QuerySet can be sliced - using Python's array-slicing syntax.
gt
delete()
filter chaining
slicing
41. 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.
db
Many-to-many relationship through an intermediate model
Custom model methods
filter(**kwargs)
42. The default for this is the name of the child class followed by '_set'.
__unicode__()
values_list(*fields)
intermediate models
reverse name
43. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
ordered
DoesNotExist
values(*fields)
none()
44. Lookup type that finds a case-insensitive regular expression match.
Proxy model
reverse name
iregex
evaluation
45. This gives your model metadata.
save()
slicing
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Meta class
46. Lookup type that tests for inclusion in a case-sensitive fashion.
create(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
contains
get_absolute_url()
47. 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()
default
filter chaining
48. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
update(**kwargs)
Abstract base class
through argument
49. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
one-to-one relationship
dates(field - kind - order='ASC')
in
50. 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
all()
Entry.objects.filter(pub_date__year=2005).delete()
MultipleObjectsReturned
aggregate(args - *kwargs)