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. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
day
related_name
Entry.objects.filter(id__in=[1 - 3 - 4])
exclude(**kwargs)
2. 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.
save()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Many-to-many relationship to self
choices tuple
3. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
week_day
select_related()
count()
exists()
4. Lookup type for date/datetime fields that finds an exact day match.
get_or_create(**kwargs)
class attributes
day
filter
5. 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.
lt
filter(**kwargs)
choices
&
6. 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
Multi-table inheritance
delete()
primary_key
F()
7. a QuerySet can be sliced - using Python's array-slicing syntax.
DoesNotExist
slicing
annotate(args - *kwargs)
day
8. Lookup type that finds a case-insensitive regular expression match.
iregex
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
primary_key
relationship spanning
9. Lookup type that returns results with a case-insensitive start sequence.
endswith
isnull
pk
istartswith
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)
Model metadata
pk
Abstract base class
QuerySet
11. This gives your model metadata.
Meta class
exact
ManyToManyField
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
12. 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
13. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
update(**kwargs)
==
in_bulk(id_list)
Restrictions on field names
14. This query finds all entries between a start date of start_date and an end date of end_date.
only(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
using(alias)
order_by(*fields)
15. These add custom "row-level" functionality to your objects. These act on a particular model instance.
iregex
in_bulk(id_list)
Custom model methods
gt
16. This query finds all entries with an id greater than 4.
filter
lt
Entry.objects.filter(id__gt=4)
unique
17. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
many-to-many relationship
id field
pickling
year
18. 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.
Manager
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
gt
19. 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.
filter chaining
gte
only(*fields)
isnull
20. Lookup type that returns results that fall into an inclusive date range.
range
ForeignKey
month
update()
21. Lookup type that returns results with a case-insensitive end sequence.
iregex
iendswith
Meta class
lte
22. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
create(**kwargs)
ordered
using(alias)
update(**kwargs)
23. Lookup type that returns results greater than or equal to a given value.
lte
isnull
gte
evaluation
24. 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
Multi-table inheritance
values_list(*fields)
relationship spanning
range
25. 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
update(**kwargs)
blank
through argument
many-to-many relationship
26. 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.
order_by(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
none()
endswith
27. This is a criterion that narrow down a QuerySet based on given parameters.
in
iendswith
lte
filter
28. 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
exclude(**kwargs)
Proxy model
gte
only(*fields)
29. Returns the most recent object in the table - by date - using the field_name provided as the date field.
select_related()
default
latest(field_name=None)
lte
30. 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
Proxy model
Multi-table inheritance
istartswith
Abstract base class
31. 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)
help_text
OneToOneField
exact
32. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
get_or_create(**kwargs)
|
get(**kwargs)
iteration
33. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
count()
isnull
month
week_day
34. This field is added automatically - but this behavior can be overridden
endswith
distinct()
id field
clear() method
35. 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.
get_absolute_url()
exists()
delete()
aggregate(args - *kwargs)
36. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
Custom model methods
choices
values(*fields)
when you add new apps to INSTALLED_APPS
37. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
OneToOneField
reverse name
filter(**kwargs)
contains
38. The default for this is the name of the child class followed by '_set'.
Meta class
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
reverse name
Q()
39. If True - the table does not permit duplicate values for this field.
reverse()
unique
in
get_absolute_url()
40. 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
lt
many-to-many relationship
iterator()
DoesNotExist
41. Lookup type that tests for inclusion in a case-sensitive fashion.
~
contains
filter(**kwargs)
values(*fields)
42. 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
exists()
one-to-one relationship
in
none()
43. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used
gt
class type
Q(question__istartswith='What')
primary_key
44. 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.
filter(**kwargs)
delete()
gt
values_list(*fields)
45. Can be used to remove all many-to-many relationships for an instance
create(**kwargs)
iendswith
relationship spanning
clear() method
46. This method immediately deletes the object and has no return value.
delete()
reverse name
DoesNotExist
range
47. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
related_name
all()
exists()
48. Lookup type that yields a case-insensitive match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iexact
all()
gt
49. If this option is True - the field is allowed to be blank. Default is False.
&
Entry.objects.filter(id__gt=4)
blank
Many-to-many relationship to self
50. Fields are specified by these
pickling
class attributes
get_absolute_url()
distinct()