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 that returns results in a given list.
Entry.objects.filter(id__in=[1 - 3 - 4])
in
id field
Manager
2. 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
class attributes
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iterator()
primary_key
3. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_absolute_url()
values(*fields)
month
4. 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.
Meta class
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
reverse name
ManyToManyField
5. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
iexact
evaluation
Multi-table inheritance
6. Lookup type that finds a case-sensitive regular expression match.
Entry.objects.filter(id__in=[1 - 3 - 4])
gte
ordered
regex
7. Fields are specified by these
filter
year
class attributes
many-to-one relationship
8. Lookup type that yields a case-insensitive match.
get(**kwargs)
iexact
exclude(**kwargs)
many-to-many relationship
9. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
through argument
year
Manager methods
pk
10. Lookup type that finds a case-insensitive regular expression match.
iregex
exact
istartswith
create(**kwargs)
11. Lookup type that returns results greater than a given value.
filter
exists()
startswith
gt
12. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
filter(**kwargs)
select_related()
one-to-one relationship
lt
13. 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
Model metadata
startswith
exists()
all()
14. Keyword shortcut for looking up an object by primary key.
using(alias)
pk
day
lte
15. 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)
Many-to-many relationship to self
intermediate models
choices
16. When to run syncdb
F()
get_or_create(**kwargs)
model
when you add new apps to INSTALLED_APPS
17. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
Proxy model
all()
iexact
18. 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.
using(alias)
gt
one-to-one relationship
default
19. 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
filter(**kwargs)
defer(*fields)
class type
create(**kwargs)
20. To activate your models
Multi-table inheritance
Q(question__istartswith='What')
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
when you add new apps to INSTALLED_APPS
21. 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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
isnull
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
through argument
22. These methods are intended to do "table-wide" things.
many-to-many relationship
Manager methods
primary_key
Entry.objects.filter(pub_date__range=(start_date - end_date))
23. 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
F()
filter
unique
update(**kwargs)
24. If this option is True - the field is allowed to be blank. Default is False.
values_list(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
blank
year
25. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
==
Entry.objects.filter(id__in=[1 - 3 - 4])
relationship spanning
26. Lookup type that returns results with a case-insensitive start sequence.
lte
istartswith
blank
values(*fields)
27. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
QuerySet
filter(**kwargs)
iregex
get_or_create(**kwargs)
28. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
order_by(*fields)
&
range
29. This field is added automatically - but this behavior can be overridden
MultipleObjectsReturned
id field
blank
class type
30. Lookup type for date/datetime fields that finds a 'day of the week' match.
all()
week_day
evaluation
istartswith
31. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
through argument
count()
filter(**kwargs)
Many-to-many relationship to self
32. This gives your model metadata.
aggregate(args - *kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Meta class
gt
33. 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()
evaluation
null
none()
Meta class
34. 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.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Meta class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exact
35. 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
MultipleObjectsReturned
relationship spanning
Many-to-many relationship to self
reverse name
36. These add custom "row-level" functionality to your objects. These act on a particular model instance.
iexact
ordered
select_related()
Custom model methods
37. 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.
ForeignKey
exclude(**kwargs)
week_day
null
38. Negation operator for Q objects.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
istartswith
model
~
39. 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.
values(*fields)
many-to-one relationship
iendswith
ManyToManyField
40. Disjunction operator for Q objects.
many-to-one relationship
unique
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
|
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.
year
Many-to-many relationship through an intermediate model
aggregate(args - *kwargs)
class type
42. 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
db
dates(field - kind - order='ASC')
in
Abstract base class
43. This model method is used for updating a ManyToManyField.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
OneToOneField
add()
in_bulk(id_list)
44. 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
annotate(args - *kwargs)
Proxy model
exact
iexact
45. If this option is True - Django will store empty values as NULL in the database. Default is False.
distinct()
|
null
using(alias)
46. Lookup type that returns results with a case-sensitive end sequence.
endswith
slicing
order_by(*fields)
ordered
47. 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.
gte
distinct()
update()
in_bulk(id_list)
48. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
lt
~
istartswith
49. 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)
Model metadata
blank
isnull
Entry.objects.filter(id__gt=4)
50. Used to get a QuerySet for a model. This is called 'objects' by default.
dates(field - kind - order='ASC')
Manager
help_text
DoesNotExist