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 takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
clear() method
filter(**kwargs)
isnull
2. 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
3. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
year
filter(**kwargs)
model
order_by(*fields)
4. Returns the most recent object in the table - by date - using the field_name provided as the date field.
values(*fields)
latest(field_name=None)
iteration
one-to-one relationship
5. 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()
default
Restrictions on field names
one-to-one relationship
6. 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.
gte
get(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
istartswith
7. If True - this field is the primary key for the model.
gt
dates(field - kind - order='ASC')
primary_key
class type
8. 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
reverse()
many-to-one relationship
Meta class
select_related()
9. Lookup type that returns results less than a given value.
lt
using(alias)
get_absolute_url()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
10. 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
11. 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.
create(**kwargs)
class attributes
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
many-to-one relationship
12. 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
reverse name
week_day
month
13. A convenience method for constructing an object and saving it all in one step.
~
create(**kwargs)
gt
many-to-many relationship
14. Lookup type that tests for inclusion in a case-sensitive fashion.
get_absolute_url()
week_day
all()
contains
15. Lookup type that returns results with a case-sensitive end sequence.
Many-to-many relationship to self
day
latest(field_name=None)
endswith
16. To activate your models
choices
ordered
iendswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
17. This is a criterion that narrow down a QuerySet based on given parameters.
==
filter
gt
exact
18. Lookup type that returns results less than or equal to a given value.
lte
Custom model methods
regex
select_related()
19. Fields are specified by these
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
class attributes
save()
20. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
unique
Many-to-many relationship to self
Entry.objects.filter(pub_date__year=2005).delete()
related_name
21. Disjunction operator for Q objects.
iexact
|
Entry.objects.filter(id__in=[1 - 3 - 4])
choices
22. 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
defer(*fields)
many-to-many relationship
isnull
|
23. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
order_by(*fields)
clear() method
evaluation
24. Manager method used to retrieve every object in a model.
latest(field_name=None)
get_or_create(**kwargs)
all()
null
25. 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.
reverse()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
iteration
relationship spanning
26. 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
exact
F()
Manager
clear() method
27. 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()
primary_key
evaluation
null
Field lookups
28. This model method saves a model instance to the database. This method has no return value.
month
create(**kwargs)
iteration
save()
29. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
Q()
update()
in_bulk(id_list)
related_name
30. If True - the table does not permit duplicate values for this field.
update(**kwargs)
regex
choices
unique
31. 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.
update()
pickling
annotate(args - *kwargs)
values_list(*fields)
32. This model method is used for updating a ManyToManyField.
add()
null
iterator()
values(*fields)
33. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
&
in_bulk(id_list)
filter(**kwargs)
34. 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
only(*fields)
model
order_by(*fields)
ordered
35. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
search
==
year
many-to-many relationship
36. Lookup type that returns results greater than a given value.
create(**kwargs)
Model metadata
Manager
gt
37. 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.
Field lookups
get_or_create(**kwargs)
ManyToManyField
using(alias)
38. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
Q(question__istartswith='What')
many-to-many relationship
&
39. 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
month
aggregate(args - *kwargs)
all()
40. Negation operator for Q objects.
iexact
class type
filter(**kwargs)
~
41. 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
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
evaluation
F()
day
Abstract base class
43. (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.
aggregate(args - *kwargs)
Restrictions on field names
pickling
intermediate models
44. 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
intermediate models
aggregate(args - *kwargs)
slicing
Entry.objects.filter(id__gt=4)
45. The default for this is the name of the child class followed by '_set'.
reverse name
|
Manager methods
==
46. Lookup type that finds a case-insensitive regular expression match.
Model metadata
iregex
relationship spanning
Abstract base class
47. 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.
QuerySet
get_absolute_url()
Q()
annotate(args - *kwargs)
48. This method immediately deletes the object and has no return value.
delete()
gte
exact
related_name
49. Lookup type that returns results that fall into an inclusive date range.
all()
range
filter(**kwargs)
null
50. 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)
gt
contains
exclude(**kwargs)