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. A convenience method for constructing an object and saving it all in one step.
count()
create(**kwargs)
Abstract base class
Q()
2. 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
istartswith
class type
update(**kwargs)
ForeignKey
3. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
latest(field_name=None)
Field lookups
Q(question__istartswith='What')
4. 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.
~
aggregate(args - *kwargs)
slicing
distinct()
5. Lookup type that returns results less than a given value.
id field
Q(question__istartswith='What')
choices tuple
lt
6. Lookup type that returns results with a case-insensitive start sequence.
Entry.objects.filter(pub_date__range=(start_date - end_date))
istartswith
regex
Manager methods
7. 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.
default
&
class type
add()
8. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
search
create(**kwargs)
iregex
==
9. Lookup type that finds a case-insensitive regular expression match.
iregex
Restrictions on field names
create(**kwargs)
values(*fields)
10. If this option is True - the field is allowed to be blank. Default is False.
aggregate(args - *kwargs)
in
blank
reverse()
11. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
==
__unicode__()
class attributes
count()
12. This query deletes all Entry objects with a pub_date year of 2005.
many-to-many relationship
Entry.objects.filter(pub_date__year=2005).delete()
distinct()
pk
13. These methods are intended to do "table-wide" things.
Manager methods
using(alias)
iregex
count()
14. 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
exact
iendswith
isnull
Abstract base class
15. This gives your model metadata.
year
Entry.objects.filter(pub_date__year=2005).delete()
iexact
Meta class
16. Manager method used to retrieve every object in a model.
all()
search
lt
startswith
17. 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.
QuerySet
search
related_name
in_bulk(id_list)
18. 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.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
ManyToManyField
Model metadata
null
19. 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
|
Many-to-many relationship through an intermediate model
exists()
intermediate models
20. 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.
|
related_name
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
pickling
21. If True - the table does not permit duplicate values for this field.
distinct()
&
update()
unique
22. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
save()
year
slicing
startswith
23. Lookup type that finds a case-sensitive regular expression match.
choices tuple
Field lookups
regex
~
24. 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.
get_absolute_url()
Manager methods
many-to-one relationship
all()
25. Lookup type for date/datetime fields that finds a 'day of the week' match.
Manager
unique
week_day
Manager methods
26. This model method is used for updating a ManyToManyField.
blank
order_by(*fields)
Field lookups
add()
27. This method immediately deletes the object and has no return value.
|
exact
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
delete()
28. 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.
lt
Many-to-many relationship to self
==
null
29. 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
30. 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
defer(*fields)
ForeignKey
iendswith
31. This query finds all entries with an id in the list [1 - 3 - 4]
range
Entry.objects.filter(id__in=[1 - 3 - 4])
pickling
regex
32. 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
33. If this option is True - Django will store empty values as NULL in the database. Default is False.
Q(question__istartswith='What')
exact
id field
null
34. 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
choices tuple
regex
DoesNotExist
F()
35. 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=2007).update(headline='Everything is the same')
Manager
choices tuple
36. 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()
select_related()
evaluation
week_day
null
37. Keyword shortcut for looking up an object by primary key.
pk
Entry.objects.filter(id__gt=4)
using(alias)
lt
38. The database that will be used if this query is executed now
gt
~
__unicode__()
db
39. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
defer(*fields)
day
range
40. 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.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
update()
filter chaining
distinct()
41. This query finds all entries between a start date of start_date and an end date of end_date.
OneToOneField
Entry.objects.filter(pub_date__range=(start_date - end_date))
reverse name
regex
42. 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
43. 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.
search
values_list(*fields)
==
many-to-one relationship
44. To activate your models
create(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
choices tuple
Entry.objects.filter(id__in=[1 - 3 - 4])
45. 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.
defer(*fields)
Multi-table inheritance
gt
Q(question__istartswith='What')
46. Used to get a QuerySet for a model. This is called 'objects' by default.
many-to-many relationship
__unicode__()
get_absolute_url()
Manager
47. 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.
isnull
none()
get(**kwargs)
iterator()
48. 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
49. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
delete()
select_related()
in_bulk(id_list)
many-to-many relationship
50. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Q()
update(**kwargs)
only(*fields)
exclude(**kwargs)