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. Exception raised by get(**kwargs) if more than one item matches the query.
Many-to-many relationship to self
MultipleObjectsReturned
iendswith
Entry.objects.filter(pub_date__year=2005).delete()
2. This method immediately deletes the object and has no return value.
clear() method
save()
delete()
many-to-one relationship
3. Lookup type that returns results with a case-sensitive start sequence.
through argument
pickling
startswith
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
4. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
null
distinct()
filter chaining
5. This model method is used for updating a ManyToManyField.
clear() method
add()
Manager
contains
6. 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.
iregex
Q()
many-to-many relationship
OneToOneField
7. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
gte
&
many-to-many relationship
pk
8. Disjunction operator for Q objects.
|
Custom model methods
iexact
==
9. 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
10. Lookup type that finds a case-insensitive regular expression match.
get_absolute_url()
iregex
latest(field_name=None)
Manager
11. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
annotate(args - *kwargs)
save()
filter(**kwargs)
Field lookups
12. Lookup type that returns results greater than or equal to a given value.
day
gt
gte
null
13. 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
get_or_create(**kwargs)
pickling
filter chaining
intermediate models
14. 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
15. Lookup type that returns results less than a given value.
lt
week_day
Many-to-many relationship to self
Q()
16. 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.
&
related_name
aggregate(args - *kwargs)
==
17. Returns a new QuerySet containing objects that match the given lookup parameters.
Entry.objects.filter(id__in=[1 - 3 - 4])
filter(**kwargs)
all()
regex
18. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
through argument
regex
filter chaining
19. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
save()
related_name
update(**kwargs)
20. 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
exists()
Abstract base class
defer(*fields)
class attributes
21. Negation operator for Q objects.
id field
~
gte
month
22. 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.
month
delete()
~
default
23. 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.
in_bulk(id_list)
create(**kwargs)
help_text
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
24. Lookup type for date/datetime fields that finds a 'day of the week' match.
in_bulk(id_list)
exists()
week_day
reverse name
25. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Proxy model
iterator()
~
month
26. Exception raised by get(**kwargs) if no items match the query.
gt
DoesNotExist
Entry.objects.filter(id__gt=4)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
27. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
pickling
ManyToManyField
related_name
exact
28. Keyword shortcut for looking up an object by primary key.
pk
iterator()
save()
values(*fields)
29. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
defer(*fields)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
unique
30. 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)
iregex
values_list(*fields)
db
31. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
reverse()
ForeignKey
ordered
32. 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)
class attributes
blank
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Model metadata
33. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
Entry.objects.filter(pub_date__year=2005).delete()
pickling
reverse()
34. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
QuerySet
aggregate(args - *kwargs)
filter(**kwargs)
none()
35. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
gte
db
search
36. 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.
pk
F()
get_absolute_url()
Q()
37. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
id field
when you add new apps to INSTALLED_APPS
many-to-one relationship
38. Lookup type that finds a case-sensitive regular expression match.
regex
all()
using(alias)
aggregate(args - *kwargs)
39. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
day
Q()
values(*fields)
Custom model methods
40. a QuerySet can be sliced - using Python's array-slicing syntax.
Abstract base class
get_or_create(**kwargs)
slicing
evaluation
41. Fields are specified by these
class attributes
blank
iendswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
42. 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.
delete()
defer(*fields)
default
__unicode__()
43. If True - the table does not permit duplicate values for this field.
filter chaining
unique
delete()
exact
44. If True - this field is the primary key for the model.
Proxy model
primary_key
Entry.objects.filter(pub_date__range=(start_date - end_date))
using(alias)
45. 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
exists()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
filter chaining
when you add new apps to INSTALLED_APPS
46. This represents a collection of objects from your database. It can have zero - one or many filters.
id field
QuerySet
slicing
annotate(args - *kwargs)
47. 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
48. Lookup type that yields a case-insensitive match.
&
iexact
exact
endswith
49. 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
isnull
reverse name
slicing
none()
50. Lookup type that returns results with a case-insensitive end sequence.
iendswith
delete()
Restrictions on field names
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)