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. Exception raised by get(**kwargs) if no items match the query.
lte
delete()
DoesNotExist
defer(*fields)
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.
Many-to-many relationship to self
isnull
pickling
Model metadata
3. 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.
db
help_text
save()
exact
4. 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)
when you add new apps to INSTALLED_APPS
update(**kwargs)
blank
5. 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
Proxy model
blank
MultipleObjectsReturned
slicing
6. Disjunction operator for Q objects.
reverse()
|
add()
Entry.objects.filter(id__gt=4)
7. Lookup type that returns results in a given list.
exists()
model
in
Field lookups
8. 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
gte
Meta class
primary_key
F()
9. A convenience method for constructing an object and saving it all in one step.
istartswith
when you add new apps to INSTALLED_APPS
create(**kwargs)
gt
10. 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)
get(**kwargs)
save()
annotate(args - *kwargs)
Model metadata
11. To activate your models
Q()
many-to-many relationship
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
search
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.
many-to-one relationship
search
Entry.objects.filter(pub_date__year=2005).delete()
clear() method
13. Lookup type that returns results with a case-insensitive start sequence.
dates(field - kind - order='ASC')
one-to-one relationship
add()
istartswith
14. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
OneToOneField
Entry.objects.filter(id__gt=4)
values(*fields)
Entry.objects.filter(id__in=[1 - 3 - 4])
15. 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.
one-to-one relationship
aggregate(args - *kwargs)
QuerySet
gt
16. Conjuntion operator for Q objects.
regex
Proxy model
year
&
17. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
Entry.objects.filter(id__in=[1 - 3 - 4])
ForeignKey
order_by(*fields)
isnull
18. Keyword shortcut for looking up an object by primary key.
pk
exists()
count()
select_related()
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
create(**kwargs)
pickling
slicing
intermediate models
20. Lookup type that returns results that fall into an inclusive date range.
filter
Q(question__istartswith='What')
range
using(alias)
21. A Python "magic method" that returns a unicode "representation" of any object.
gte
add()
intermediate models
__unicode__()
22. 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
~
exists()
reverse name
Q(question__istartswith='What')
23. Lookup type that finds a case-sensitive regular expression match.
regex
select_related()
default
lte
24. Lookup type that returns results greater than a given value.
Q()
gt
count()
help_text
25. The database that will be used if this query is executed now
db
Q(question__istartswith='What')
Abstract base class
Entry.objects.filter(pub_date__range=(start_date - end_date))
26. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
in_bulk(id_list)
add()
aggregate(args - *kwargs)
27. Can be used to remove all many-to-many relationships for an instance
clear() method
filter(**kwargs)
primary_key
unique
28. Lookup type that returns results less than a given value.
reverse name
ManyToManyField
lt
gt
29. 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.
Manager
filter chaining
reverse()
contains
30. 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.
update(**kwargs)
related_name
get(**kwargs)
month
31. This model method saves a model instance to the database. This method has no return value.
|
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
save()
many-to-many relationship
32. 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
get_absolute_url()
only(*fields)
add()
Restrictions on field names
33. This is a criterion that narrow down a QuerySet based on given parameters.
filter
intermediate models
__unicode__()
all()
34. Lookup type that returns results with a case-insensitive end sequence.
evaluation
Manager methods
iendswith
in
35. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
Multi-table inheritance
when you add new apps to INSTALLED_APPS
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
36. 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
iterator()
Entry.objects.filter(id__in=[1 - 3 - 4])
create(**kwargs)
reverse name
37. Lookup type for date/datetime fields that finds a 'day of the week' match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Many-to-many relationship to self
week_day
aggregate(args - *kwargs)
38. (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.
through argument
Abstract base class
when you add new apps to INSTALLED_APPS
Restrictions on field names
39. 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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
OneToOneField
Entry.objects.filter(id__gt=4)
iregex
40. 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.
class attributes
using(alias)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
==
41. 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.
iregex
endswith
year
get_absolute_url()
42. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
class type
isnull
filter(**kwargs)
unique
43. The first element in this iterable is the value that will be stored in the database - the second element will be displayed by the admin interface - or in a ModelChoiceField.
|
slicing
Q(question__istartswith='What')
choices tuple
44. 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
45. 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.
MultipleObjectsReturned
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
only(*fields)
46. 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.
Field lookups
filter
update()
filter(**kwargs)
47. 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
order_by(*fields)
Q(question__istartswith='What')
all()
blank
48. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
|
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_or_create(**kwargs)
one-to-one relationship
49. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
OneToOneField
ordered
related_name
primary_key
50. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Entry.objects.filter(pub_date__year=2005).delete()
related_name
db
default