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. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
many-to-many relationship
get_or_create(**kwargs)
relationship spanning
2. Used to get a QuerySet for a model. This is called 'objects' by default.
delete()
choices tuple
values(*fields)
Manager
3. what the field _______ determines: (1) The database column type (e.g. INTEGER - VARCHAR); (2) The widget to use in Django's admin interface - if you care to use it (e.g. <input type="text"> - <select>); (3) The minimal validation requirements - used
class type
intermediate models
range
Restrictions on field names
4. A convenience method for constructing an object and saving it all in one step.
ordered
create(**kwargs)
get(**kwargs)
choices tuple
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
defer(*fields)
many-to-many relationship
F()
choices tuple
6. Lookup type that returns results that fall into an inclusive date range.
delete()
distinct()
range
lte
7. 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.
primary_key
__unicode__()
annotate(args - *kwargs)
order_by(*fields)
8. Lookup type that returns results greater than or equal to a given value.
gte
when you add new apps to INSTALLED_APPS
exists()
DoesNotExist
9. Lookup type that tests for inclusion in a case-sensitive fashion.
Meta class
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
reverse name
contains
10. Lookup type for date/datetime fields that finds an exact day match.
filter(**kwargs)
day
week_day
&
11. This gives your model metadata.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
year
null
Meta class
12. 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
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
dates(field - kind - order='ASC')
delete()
13. 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.
ForeignKey
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
iteration
reverse()
14. A convenience method for looking up an object with the given kwargs - creating one if necessary.
default
Custom model methods
db
get_or_create(**kwargs)
15. 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
choices tuple
Manager
through argument
Q(question__istartswith='What')
16. If True - this field is the primary key for the model.
evaluation
primary_key
default
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
17. To activate your models
Restrictions on field names
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
count()
get_or_create(**kwargs)
18. Lookup type that finds a case-insensitive regular expression match.
model
iregex
ForeignKey
only(*fields)
19. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
many-to-many relationship
endswith
values(*fields)
class attributes
20. 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.
choices
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
default
month
21. 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
22. Adds to each object in the QuerySet with the provided list of aggregate values (averages - sums - etc) that have been computed over the objects that are related to the objects in the QuerySet. Each argument to this is content that will be added to ea
aggregate(args - *kwargs)
all()
intermediate models
annotate(args - *kwargs)
23. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
aggregate(args - *kwargs)
model
month
~
24. Lookup type that returns results less than or equal to a given value.
update(**kwargs)
intermediate models
contains
lte
25. This model method saves a model instance to the database. This method has no return value.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
save()
many-to-many relationship
Q(question__istartswith='What')
26. This method immediately deletes the object and has no return value.
delete()
reverse name
Multi-table inheritance
filter chaining
27. 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.
class type
many-to-one relationship
&
id field
28. 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.
order_by(*fields)
aggregate(args - *kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Q()
29. 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.
update()
reverse()
delete()
endswith
30. Returns a new QuerySet containing objects that match the given lookup parameters.
F()
filter(**kwargs)
distinct()
OneToOneField
31. 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.
through argument
search
distinct()
Multi-table inheritance
32. A Python "magic method" that returns a unicode "representation" of any object.
model
__unicode__()
values(*fields)
aggregate(args - *kwargs)
33. This field is added automatically - but this behavior can be overridden
exists()
Model metadata
save()
id field
34. Lookup type that returns results less than a given value.
lt
==
reverse name
MultipleObjectsReturned
35. Lookup type that returns results with a case-insensitive end sequence.
iendswith
none()
latest(field_name=None)
choices
36. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
class type
Entry.objects.filter(pub_date__range=(start_date - end_date))
iteration
QuerySet
37. Disjunction operator for Q objects.
|
latest(field_name=None)
delete()
add()
38. 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
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.
Many-to-many relationship through an intermediate model
month
lt
get_absolute_url()
40. If True - the table does not permit duplicate values for this field.
unique
clear() method
iregex
none()
41. Keyword shortcut for looking up an object by primary key.
gte
pk
default
in
42. If this option is True - Django will store empty values as NULL in the database. Default is False.
F()
null
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
latest(field_name=None)
43. The database that will be used if this query is executed now
db
~
gte
latest(field_name=None)
44. (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.
QuerySet
only(*fields)
Restrictions on field names
year
45. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
many-to-one relationship
add()
distinct()
46. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Entry.objects.filter(id__gt=4)
Entry.objects.filter(pub_date__range=(start_date - end_date))
|
distinct()
47. Exception raised by get(**kwargs) if no items match the query.
Manager methods
lte
DoesNotExist
range
48. Lookup type that finds a case-sensitive regular expression match.
blank
regex
reverse name
filter(**kwargs)
49. This model method is used for updating a ManyToManyField.
one-to-one relationship
Meta class
only(*fields)
add()
50. This represents a collection of objects from your database. It can have zero - one or many filters.
default
QuerySet
regex
delete()