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. 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
2. This gives your model metadata.
DoesNotExist
Meta class
relationship spanning
select_related()
3. Lookup type that yields a case-insensitive match.
pickling
iexact
QuerySet
get_absolute_url()
4. This field is added automatically - but this behavior can be overridden
gt
id field
none()
regex
5. 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
get(**kwargs)
defer(*fields)
update()
startswith
6. Exception raised by get(**kwargs) if more than one item matches the query.
exists()
&
clear() method
MultipleObjectsReturned
7. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
|
==
distinct()
count()
8. (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.
Restrictions on field names
pk
~
help_text
9. Lookup type that returns results less than or equal to a given value.
lt
lte
defer(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
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
iendswith
gte
get_absolute_url()
11. Lookup type that returns results that fall into an inclusive date range.
model
range
delete()
add()
12. Can be used to remove all many-to-many relationships for an instance
exclude(**kwargs)
OneToOneField
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
clear() method
13. Lookup type that returns results less than a given value.
iregex
Manager methods
lt
search
14. 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.
|
Q()
class attributes
many-to-one relationship
15. a QuerySet can be sliced - using Python's array-slicing syntax.
OneToOneField
slicing
all()
MultipleObjectsReturned
16. 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
select_related()
__unicode__()
save()
unique
17. 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
day
add()
QuerySet
Proxy model
18. Lookup type that tests for inclusion in a case-sensitive fashion.
count()
blank
contains
id field
19. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
iteration
get(**kwargs)
update()
Field lookups
20. These add custom "row-level" functionality to your objects. These act on a particular model instance.
==
Custom model methods
one-to-one relationship
default
21. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Abstract base class
get(**kwargs)
latest(field_name=None)
related_name
22. Lookup type that finds a case-insensitive regular expression match.
Proxy model
iregex
evaluation
defer(*fields)
23. This query finds all entries between a start date of start_date and an end date of end_date.
help_text
gt
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
24. 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.
in_bulk(id_list)
help_text
related_name
using(alias)
25. 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
class attributes
Abstract base class
month
pk
26. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Abstract base class
db
lte
month
27. This query deletes all Entry objects with a pub_date year of 2005.
only(*fields)
MultipleObjectsReturned
Entry.objects.filter(pub_date__year=2005).delete()
blank
28. Disjunction operator for Q objects.
day
|
lte
distinct()
29. 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.
Manager
ordered
update()
default
30. 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
class attributes
lte
intermediate models
related_name
31. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
choices
Many-to-many relationship through an intermediate model
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
all()
32. Lookup type that returns results greater than a given value.
gt
count()
Multi-table inheritance
all()
33. 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
34. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
get_absolute_url()
primary_key
select_related()
35. If True - the table does not permit duplicate values for this field.
unique
only(*fields)
Entry.objects.filter(id__in=[1 - 3 - 4])
values(*fields)
36. Manager method used to retrieve every object in a model.
all()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
range
Manager methods
37. 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)
|
iterator()
38. 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
lt
through argument
ManyToManyField
intermediate models
39. 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.
gte
iendswith
get_absolute_url()
pk
40. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
isnull
filter(**kwargs)
Multi-table inheritance
order_by(*fields)
41. 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.
gt
Restrictions on field names
exact
Meta class
42. This query finds all entries with an id in the list [1 - 3 - 4]
startswith
clear() method
Custom model methods
Entry.objects.filter(id__in=[1 - 3 - 4])
43. 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
&
ForeignKey
exists()
Multi-table inheritance
44. 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)
create(**kwargs)
filter
Entry.objects.filter(pub_date__year=2005).delete()
45. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
annotate(args - *kwargs)
only(*fields)
all()
46. This is a criterion that narrow down a QuerySet based on given parameters.
filter
range
update()
Many-to-many relationship to self
47. 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
reverse()
none()
|
OneToOneField
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.
using(alias)
many-to-one relationship
reverse()
aggregate(args - *kwargs)
49. These methods are intended to do "table-wide" things.
primary_key
Abstract base class
Manager methods
add()
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.
many-to-many relationship
ManyToManyField
get_or_create(**kwargs)
values_list(*fields)