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. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
values(*fields)
clear() method
unique
model
2. 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
through argument
create(**kwargs)
exists()
startswith
3. Lookup type that returns results with a case-sensitive start sequence.
many-to-one relationship
startswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
4. Manager method used to retrieve every object in a model.
regex
one-to-one relationship
clear() method
all()
5. 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.
slicing
aggregate(args - *kwargs)
Entry.objects.filter(id__gt=4)
get_absolute_url()
6. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
iendswith
distinct()
DoesNotExist
count()
7. The default for this is the name of the child class followed by '_set'.
latest(field_name=None)
Custom model methods
reverse name
blank
8. 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
9. Lookup type that returns results less than a given value.
lt
day
select_related()
get(**kwargs)
10. Returns a new QuerySet containing objects that match the given lookup parameters.
add()
one-to-one relationship
week_day
filter(**kwargs)
11. Disjunction operator for Q objects.
|
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
create(**kwargs)
choices tuple
12. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
iendswith
db
unique
filter(**kwargs)
13. Fields are specified by these
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
class attributes
evaluation
month
14. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
iterator()
istartswith
ordered
15. 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
16. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
gt
dates(field - kind - order='ASC')
class attributes
17. 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
iteration
aggregate(args - *kwargs)
many-to-many relationship
intermediate models
18. 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.
get_or_create(**kwargs)
class type
in_bulk(id_list)
Entry.objects.filter(id__in=[1 - 3 - 4])
19. Exception raised by get(**kwargs) if no items match the query.
Restrictions on field names
order_by(*fields)
Many-to-many relationship through an intermediate model
DoesNotExist
20. 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.
blank
using(alias)
many-to-one relationship
exact
21. If True - the table does not permit duplicate values for this field.
unique
slicing
many-to-one relationship
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
22. Lookup type that returns results less than or equal to a given value.
MultipleObjectsReturned
Entry.objects.filter(id__gt=4)
lte
filter(**kwargs)
23. 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.
istartswith
pickling
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
24. Lookup type that finds a case-insensitive regular expression match.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
iregex
OneToOneField
gte
25. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
~
Q()
filter(**kwargs)
26. 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
Meta class
get_or_create(**kwargs)
ordered
27. Lookup type that yields a case-insensitive match.
range
class attributes
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iexact
28. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
isnull
Meta class
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
one-to-one relationship
29. 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.
contains
help_text
primary_key
Many-to-many relationship to self
30. Lookup type that finds a case-sensitive regular expression match.
null
choices
regex
ordered
31. 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
update(**kwargs)
Restrictions on field names
through argument
only(*fields)
32. Lookup type that returns results with a case-sensitive end sequence.
search
Manager
endswith
ManyToManyField
33. 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
all()
default
week_day
select_related()
34. 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
35. These add custom "row-level" functionality to your objects. These act on a particular model instance.
annotate(args - *kwargs)
Custom model methods
iexact
id field
36. a QuerySet can be sliced - using Python's array-slicing syntax.
pk
slicing
contains
values(*fields)
37. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
Proxy model
update(**kwargs)
save()
38. Lookup type that returns results with a case-insensitive start sequence.
class attributes
get_or_create(**kwargs)
istartswith
relationship spanning
39. 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.
Entry.objects.filter(id__gt=4)
ForeignKey
Custom model methods
Proxy model
40. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
Meta class
Field lookups
delete()
41. 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.
db
get_absolute_url()
Entry.objects.filter(id__gt=4)
order_by(*fields)
42. This method immediately deletes the object and has no return value.
iexact
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
delete()
gte
43. 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
related_name
==
relationship spanning
Meta class
44. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Restrictions on field names
add()
ManyToManyField
distinct()
45. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iterator()
Proxy model
46. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
gte
month
update()
aggregate(args - *kwargs)
47. Used to get a QuerySet for a model. This is called 'objects' by default.
db
iregex
Manager
pickling
48. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
exact
year
pk
values(*fields)
49. 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.
Abstract base class
get(**kwargs)
order_by(*fields)
Q(question__istartswith='What')
50. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
Abstract base class
Manager methods
Entry.objects.filter(id__in=[1 - 3 - 4])
search