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 this option is True - the field is allowed to be blank. Default is False.
blank
F()
Entry.objects.filter(pub_date__range=(start_date - end_date))
istartswith
2. Lookup type that returns results greater than a given value.
filter(**kwargs)
gt
Entry.objects.filter(id__in=[1 - 3 - 4])
many-to-many relationship
3. This method immediately deletes the object and has no return value.
delete()
Entry.objects.filter(id__gt=4)
order_by(*fields)
get(**kwargs)
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.
Q(question__istartswith='What')
values_list(*fields)
reverse name
Entry.objects.filter(id__gt=4)
5. Lookup type that returns results with a case-insensitive start sequence.
~
Model metadata
istartswith
delete()
6. 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
help_text
null
annotate(args - *kwargs)
7. Negation operator for Q objects.
~
range
filter(**kwargs)
in_bulk(id_list)
8. 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
9. 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
pk
many-to-many relationship
iregex
only(*fields)
10. 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.
related_name
many-to-one relationship
filter chaining
Field lookups
11. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
many-to-one relationship
~
null
12. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
many-to-one relationship
null
Manager methods
13. 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.
Q()
reverse()
many-to-one relationship
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
14. Keyword shortcut for looking up an object by primary key.
pk
F()
update(**kwargs)
range
15. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Many-to-many relationship through an intermediate model
class attributes
defer(*fields)
get_or_create(**kwargs)
16. 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()
Multi-table inheritance
filter chaining
when you add new apps to INSTALLED_APPS
17. Lookup type that yields a case-insensitive match.
Manager methods
iexact
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
18. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
null
Many-to-many relationship through an intermediate model
year
Model metadata
19. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
gte
Field lookups
isnull
Q()
20. Lookup type that returns results with a case-sensitive end sequence.
lte
latest(field_name=None)
isnull
endswith
21. Exception raised by get(**kwargs) if no items match the query.
values_list(*fields)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
DoesNotExist
add()
22. Manager method used to retrieve every object in a model.
gt
evaluation
all()
select_related()
23. 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
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
choices tuple
relationship spanning
iexact
Custom model methods
25. 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.
get_absolute_url()
OneToOneField
filter chaining
blank
26. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
MultipleObjectsReturned
Proxy model
intermediate models
27. 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
Abstract base class
select_related()
intermediate models
week_day
28. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
endswith
contains
exclude(**kwargs)
help_text
29. To activate your models
default
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
class type
many-to-many relationship
30. 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.
order_by(*fields)
db
ManyToManyField
unique
31. Lookup type for date/datetime fields that finds an exact day match.
ForeignKey
id field
Entry.objects.filter(pub_date__year=2005).delete()
day
32. 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.
delete()
Q(question__istartswith='What')
one-to-one relationship
order_by(*fields)
33. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
update()
F()
values(*fields)
when you add new apps to INSTALLED_APPS
34. These add custom "row-level" functionality to your objects. These act on a particular model instance.
defer(*fields)
get(**kwargs)
Custom model methods
many-to-many relationship
35. 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.
choices tuple
week_day
ForeignKey
Many-to-many relationship through an intermediate model
36. 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)
select_related()
get_absolute_url()
ManyToManyField
Model metadata
37. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
create(**kwargs)
related_name
regex
dates(field - kind - order='ASC')
38. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Meta class
blank
one-to-one relationship
using(alias)
39. Exception raised by get(**kwargs) if more than one item matches the query.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
reverse name
help_text
MultipleObjectsReturned
40. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
Restrictions on field names
aggregate(args - *kwargs)
help_text
filter chaining
41. 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.
get(**kwargs)
default
MultipleObjectsReturned
class type
42. 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
filter
Proxy model
model
range
43. This field is added automatically - but this behavior can be overridden
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Abstract base class
blank
id field
44. 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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
gte
class attributes
45. Returns the most recent object in the table - by date - using the field_name provided as the date field.
DoesNotExist
latest(field_name=None)
select_related()
Model metadata
46. 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
clear() method
save()
exists()
primary_key
47. Fields are specified by these
DoesNotExist
class attributes
default
in_bulk(id_list)
48. 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
exact
class attributes
intermediate models
OneToOneField
49. This is a criterion that narrow down a QuerySet based on given parameters.
Meta class
relationship spanning
db
filter
50. Conjuntion operator for Q objects.
&
none()
distinct()
get(**kwargs)