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 True - this field is the primary key for the model.
intermediate models
primary_key
evaluation
search
2. 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.
blank
clear() method
exact
ManyToManyField
3. Negation operator for Q objects.
~
Field lookups
all()
lt
4. Lookup type that returns results in a given list.
endswith
blank
in
~
5. These add custom "row-level" functionality to your objects. These act on a particular model instance.
save()
in
Custom model methods
get_or_create(**kwargs)
6. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
default
count()
none()
startswith
7. This model method saves a model instance to the database. This method has no return value.
save()
Proxy model
all()
gte
8. This query finds all entries with an id in the list [1 - 3 - 4]
relationship spanning
iregex
primary_key
Entry.objects.filter(id__in=[1 - 3 - 4])
9. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
contains
annotate(args - *kwargs)
primary_key
10. 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.
help_text
iexact
save()
exclude(**kwargs)
11. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
lt
ForeignKey
Entry.objects.filter(pub_date__year=2005).delete()
12. Disjunction operator for Q objects.
pickling
Proxy model
values(*fields)
|
13. This query finds all entries between a start date of start_date and an end date of end_date.
day
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
clear() method
14. 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()
in
range
==
15. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
Entry.objects.filter(pub_date__year=2005).delete()
class type
&
16. 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
choices
id field
choices tuple
defer(*fields)
17. Lookup type that returns results greater than or equal to a given value.
gte
in
create(**kwargs)
many-to-many relationship
18. Keyword shortcut for looking up an object by primary key.
Multi-table inheritance
pk
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
istartswith
19. Conjuntion operator for Q objects.
iterator()
Multi-table inheritance
iexact
&
20. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
annotate(args - *kwargs)
get(**kwargs)
ForeignKey
related_name
21. 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.
Custom model methods
search
all()
Multi-table inheritance
22. Lookup type that returns results greater than a given value.
~
gt
when you add new apps to INSTALLED_APPS
through argument
23. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
Field lookups
model
when you add new apps to INSTALLED_APPS
==
24. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
day
Custom model methods
search
25. 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.
OneToOneField
all()
ForeignKey
create(**kwargs)
26. 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
27. Lookup type that finds a case-sensitive regular expression match.
regex
evaluation
dates(field - kind - order='ASC')
Q(question__istartswith='What')
28. 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.
delete()
class type
pickling
==
29. This model method is used for updating a ManyToManyField.
through argument
clear() method
update(**kwargs)
add()
30. 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
using(alias)
blank
relationship spanning
values(*fields)
31. 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.
aggregate(args - *kwargs)
ManyToManyField
lte
order_by(*fields)
32. 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.
Field lookups
choices tuple
when you add new apps to INSTALLED_APPS
order_by(*fields)
33. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
pk
delete()
filter(**kwargs)
primary_key
34. 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.
OneToOneField
Entry.objects.filter(pub_date__year=2005).delete()
using(alias)
QuerySet
35. A convenience method for constructing an object and saving it all in one step.
lt
using(alias)
reverse name
create(**kwargs)
36. 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
unique
OneToOneField
class attributes
exists()
37. Lookup type for date/datetime fields that finds an exact day match.
Field lookups
day
DoesNotExist
only(*fields)
38. 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.
pickling
gte
order_by(*fields)
in_bulk(id_list)
39. Returns the most recent object in the table - by date - using the field_name provided as the date field.
filter chaining
latest(field_name=None)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
istartswith
40. (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.
gte
Entry.objects.filter(pub_date__range=(start_date - end_date))
Restrictions on field names
get_absolute_url()
41. 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.
slicing
Many-to-many relationship through an intermediate model
lt
get(**kwargs)
42. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Meta class
distinct()
update()
iregex
43. Can be used to remove all many-to-many relationships for an instance
DoesNotExist
clear() method
in
contains
44. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
year
relationship spanning
Abstract base class
45. 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
values_list(*fields)
unique
delete()
F()
46. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
pk
distinct()
class attributes
47. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
Entry.objects.filter(id__gt=4)
update()
week_day
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
48. 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.
get_absolute_url()
lt
update(**kwargs)
many-to-one relationship
49. If this option is True - Django will store empty values as NULL in the database. Default is False.
dates(field - kind - order='ASC')
filter(**kwargs)
iterator()
null
50. 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()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
delete()
reverse()