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. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
Entry.objects.filter(pub_date__range=(start_date - end_date))
clear() method
month
2. A convenience method for looking up an object with the given kwargs - creating one if necessary.
lte
get_or_create(**kwargs)
when you add new apps to INSTALLED_APPS
slicing
3. 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.
help_text
search
default
DoesNotExist
4. Lookup type that tests for inclusion in a case-sensitive fashion.
iteration
QuerySet
Q(question__istartswith='What')
contains
5. 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
using(alias)
all()
annotate(args - *kwargs)
Many-to-many relationship to self
6. Returns a new QuerySet containing objects that match the given lookup parameters.
count()
filter(**kwargs)
when you add new apps to INSTALLED_APPS
Meta class
7. Fields are specified by these
Custom model methods
class attributes
range
pk
8. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
primary_key
week_day
create(**kwargs)
9. 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
none()
lte
create(**kwargs)
order_by(*fields)
10. The database that will be used if this query is executed now
Model metadata
db
filter
filter(**kwargs)
11. Lookup type that returns results less than or equal to a given value.
lte
in
ManyToManyField
related_name
12. 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
intermediate models
istartswith
defer(*fields)
Q()
13. Lookup type that returns results with a case-insensitive end sequence.
through argument
iendswith
month
OneToOneField
14. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
help_text
month
in_bulk(id_list)
all()
15. 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.
regex
all()
get_absolute_url()
delete()
16. 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.
Many-to-many relationship through an intermediate model
get(**kwargs)
MultipleObjectsReturned
class type
17. 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
in
endswith
choices tuple
18. 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.
exists()
delete()
regex
many-to-one relationship
19. 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
blank
exists()
exact
annotate(args - *kwargs)
20. 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
using(alias)
all()
relationship spanning
==
21. 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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get_or_create(**kwargs)
gt
search
22. 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.
distinct()
defer(*fields)
filter chaining
using(alias)
23. Lookup type that returns results that fall into an inclusive date range.
one-to-one relationship
range
null
ManyToManyField
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.
annotate(args - *kwargs)
endswith
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
regex
25. This query finds all entries with an id in the list [1 - 3 - 4]
primary_key
__unicode__()
Entry.objects.filter(id__in=[1 - 3 - 4])
values_list(*fields)
26. 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.
many-to-many relationship
unique
Manager
get(**kwargs)
27. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
reverse()
values(*fields)
search
28. 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
29. Keyword shortcut for looking up an object by primary key.
pk
Q()
update()
get_or_create(**kwargs)
30. 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.
Q()
delete()
clear() method
choices
31. Negation operator for Q objects.
get(**kwargs)
one-to-one relationship
~
exclude(**kwargs)
32. This is a criterion that narrow down a QuerySet based on given parameters.
reverse name
values_list(*fields)
pickling
filter
33. 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)
Custom model methods
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
primary_key
Model metadata
34. 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.
order_by(*fields)
update()
iendswith
==
35. When to run syncdb
when you add new apps to INSTALLED_APPS
pk
in_bulk(id_list)
Entry.objects.filter(pub_date__year=2005).delete()
36. 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
ForeignKey
isnull
lt
37. 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
OneToOneField
exclude(**kwargs)
iterator()
Entry.objects.filter(pub_date__year=2005).delete()
38. 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()
update(**kwargs)
iteration
evaluation
model
39. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
class attributes
all()
using(alias)
40. 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.
create(**kwargs)
count()
when you add new apps to INSTALLED_APPS
ManyToManyField
41. Lookup type that returns results with a case-sensitive start sequence.
endswith
startswith
model
choices
42. Manager method used to retrieve every object in a model.
all()
get(**kwargs)
isnull
distinct()
43. 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
44. Lookup type that returns results with a case-sensitive end sequence.
endswith
filter
regex
id field
45. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Restrictions on field names
related_name
search
gte
46. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
Many-to-many relationship to self
gt
QuerySet
47. 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
Abstract base class
delete()
Proxy model
isnull
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. (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.
Q()
none()
Abstract base class
Restrictions on field names
50. If True - this field is the primary key for the model.
primary_key
Many-to-many relationship to self
endswith
order_by(*fields)