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. Can be used to remove all many-to-many relationships for an instance
ordered
filter(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
clear() method
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.
pickling
week_day
Many-to-many relationship through an intermediate model
range
3. This gives your model metadata.
Entry.objects.filter(id__gt=4)
filter(**kwargs)
Meta class
select_related()
4. Lookup type that returns results with a case-sensitive end sequence.
|
endswith
OneToOneField
class attributes
5. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
day
exclude(**kwargs)
blank
Manager methods
6. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
Restrictions on field names
relationship spanning
null
Many-to-many relationship through an intermediate model
7. 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.
in_bulk(id_list)
search
exclude(**kwargs)
get_absolute_url()
8. 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
year
only(*fields)
F()
intermediate models
9. Disjunction operator for Q objects.
__unicode__()
|
add()
ManyToManyField
10. 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()
MultipleObjectsReturned
all()
Manager
evaluation
11. 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
contains
Multi-table inheritance
F()
none()
12. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
filter
ForeignKey
iteration
order_by(*fields)
13. 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
14. Lookup type for date/datetime fields that finds a 'day of the week' match.
clear() method
week_day
delete()
create(**kwargs)
15. 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
16. This query finds all entries with an id greater than 4.
gte
Entry.objects.filter(id__gt=4)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
istartswith
17. Lookup type that returns results greater than a given value.
exact
gt
dates(field - kind - order='ASC')
MultipleObjectsReturned
18. Lookup type that finds a case-insensitive regular expression match.
iregex
isnull
default
evaluation
19. 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.
day
OneToOneField
ForeignKey
using(alias)
20. This represents a collection of objects from your database. It can have zero - one or many filters.
through argument
QuerySet
Meta class
pickling
21. Keyword shortcut for looking up an object by primary key.
order_by(*fields)
Q(question__istartswith='What')
update()
pk
22. To activate your models
ordered
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
update(**kwargs)
db
23. 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.
Q()
relationship spanning
iexact
Meta class
24. 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
iregex
using(alias)
all()
related_name
25. These add custom "row-level" functionality to your objects. These act on a particular model instance.
DoesNotExist
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Custom model methods
intermediate models
26. 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)
gte
save()
gt
27. Returns the object matching the given lookup parameters
get(**kwargs)
create(**kwargs)
add()
clear() method
28. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
Multi-table inheritance
iterator()
evaluation
29. Lookup type that returns results greater than or equal to a given value.
aggregate(args - *kwargs)
get_or_create(**kwargs)
defer(*fields)
gte
30. This model method is used for updating a ManyToManyField.
get_absolute_url()
add()
related_name
ForeignKey
31. This is a criterion that narrow down a QuerySet based on given parameters.
many-to-one relationship
month
filter
filter(**kwargs)
32. 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
through argument
unique
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
class type
33. Lookup type that returns results less than or equal to a given value.
dates(field - kind - order='ASC')
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values(*fields)
lte
34. If this option is True - the field is allowed to be blank. Default is False.
blank
slicing
endswith
none()
35. (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.
Restrictions on field names
intermediate models
Manager methods
relationship spanning
36. This model method saves a model instance to the database. This method has no return value.
iexact
id field
save()
using(alias)
37. 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.
Restrictions on field names
defer(*fields)
exclude(**kwargs)
update()
38. A convenience method for looking up an object with the given kwargs - creating one if necessary.
values(*fields)
Custom model methods
get_or_create(**kwargs)
exists()
39. This method immediately deletes the object and has no return value.
Entry.objects.filter(id__in=[1 - 3 - 4])
delete()
intermediate models
when you add new apps to INSTALLED_APPS
40. 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.
values_list(*fields)
exact
primary_key
regex
41. Lookup type that tests for inclusion in a case-sensitive fashion.
update()
reverse()
endswith
contains
42. Conjuntion operator for Q objects.
choices tuple
&
search
contains
43. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
exclude(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
using(alias)
44. This method is for controlling which database the QuerySet will be evaluated against if you are using more than one database. The only argument this method takes is the alias of a database - as defined in DATABASES.
pk
using(alias)
__unicode__()
Proxy model
45. 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.
help_text
distinct()
choices
only(*fields)
46. 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.
range
iterator()
endswith
delete()
47. Lookup type for date/datetime fields that finds an exact day match.
day
none()
in_bulk(id_list)
primary_key
48. The default for this is the name of the child class followed by '_set'.
update()
reverse name
through argument
slicing
49. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
regex
year
ordered
many-to-many relationship
50. Lookup type that returns results that fall into an inclusive date range.
latest(field_name=None)
range
Field lookups
MultipleObjectsReturned