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. 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.
Many-to-many relationship to self
unique
select_related()
db
2. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
filter chaining
update()
regex
3. 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
Proxy model
none()
==
delete()
4. This query finds all entries with an id in the list [1 - 3 - 4]
values_list(*fields)
save()
annotate(args - *kwargs)
Entry.objects.filter(id__in=[1 - 3 - 4])
5. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.
exclude(**kwargs)
get(**kwargs)
filter chaining
reverse()
6. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
istartswith
id field
exact
==
7. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
none()
get_absolute_url()
values(*fields)
8. 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
9. The default for this is the name of the child class followed by '_set'.
reverse name
Abstract base class
Q()
Many-to-many relationship through an intermediate model
10. Fields are specified by these
all()
Manager methods
Proxy model
class attributes
11. 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)
in
in_bulk(id_list)
iteration
12. 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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
update(**kwargs)
order_by(*fields)
Abstract base class
13. Returns the object matching the given lookup parameters
get(**kwargs)
all()
evaluation
values_list(*fields)
14. 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.
update(**kwargs)
range
primary_key
Many-to-many relationship through an intermediate model
15. The database that will be used if this query is executed now
db
iendswith
range
intermediate models
16. 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
search
all()
Abstract base class
choices
17. 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.
regex
lt
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)
18. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Proxy model
blank
lte
19. Lookup type that returns results greater than or equal to a given value.
iendswith
Entry.objects.filter(id__in=[1 - 3 - 4])
order_by(*fields)
gte
20. Lookup type that returns results with a case-sensitive end sequence.
endswith
default
iterator()
in
21. 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()
default
get_absolute_url()
evaluation
OneToOneField
22. This query finds all entries between a start date of start_date and an end date of end_date.
using(alias)
Entry.objects.filter(pub_date__range=(start_date - end_date))
choices tuple
relationship spanning
23. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Q()
range
Multi-table inheritance
24. Disjunction operator for Q objects.
filter
Proxy model
|
Multi-table inheritance
25. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
exclude(**kwargs)
pickling
choices
26. This query deletes all Entry objects with a pub_date year of 2005.
year
regex
Entry.objects.filter(pub_date__year=2005).delete()
values(*fields)
27. Lookup type that returns results in a given list.
QuerySet
day
in
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
28. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
istartswith
iterator()
when you add new apps to INSTALLED_APPS
29. When to run syncdb
when you add new apps to INSTALLED_APPS
intermediate models
Restrictions on field names
Field lookups
30. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
DoesNotExist
Manager methods
Entry.objects.filter(id__in=[1 - 3 - 4])
31. These methods are intended to do "table-wide" things.
Manager methods
values_list(*fields)
only(*fields)
db
32. This method immediately deletes the object and has no return value.
through argument
Restrictions on field names
delete()
only(*fields)
33. Returns a new QuerySet containing objects that match the given lookup parameters.
startswith
Multi-table inheritance
distinct()
filter(**kwargs)
34. This represents a collection of objects from your database. It can have zero - one or many filters.
Q()
QuerySet
Entry.objects.filter(id__gt=4)
one-to-one relationship
35. If True - the table does not permit duplicate values for this field.
Q()
DoesNotExist
unique
Manager
36. Negation operator for Q objects.
contains
using(alias)
~
select_related()
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
iterator()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
update(**kwargs)
annotate(args - *kwargs)
38. 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
39. A convenience method for constructing an object and saving it all in one step.
intermediate models
pk
create(**kwargs)
~
40. 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.
all()
Restrictions on field names
get_absolute_url()
pickling
41. 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.
choices
annotate(args - *kwargs)
class type
contains
42. 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
Many-to-many relationship through an intermediate model
choices
through argument
regex
43. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
values_list(*fields)
Many-to-many relationship to self
Field lookups
MultipleObjectsReturned
44. Lookup type that returns results greater than a given value.
Entry.objects.filter(id__in=[1 - 3 - 4])
update(**kwargs)
gt
clear() method
45. 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.
blank
OneToOneField
class attributes
get_absolute_url()
46. Lookup type for date/datetime fields that finds an exact day match.
day
Manager
update(**kwargs)
Field lookups
47. 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
F()
relationship spanning
delete()
|
48. Lookup type that returns results with a case-insensitive end sequence.
Multi-table inheritance
Meta class
&
iendswith
49. To activate your models
search
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
in
Multi-table inheritance
50. 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)
startswith
create(**kwargs)
==