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 Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Restrictions on field names
update()
filter(**kwargs)
contains
2. 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.
get(**kwargs)
choices tuple
reverse name
get_absolute_url()
3. When to run syncdb
gt
when you add new apps to INSTALLED_APPS
ordered
exists()
4. 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
values_list(*fields)
all()
get(**kwargs)
5. An iterable (e.g. - a list or tuple) of 2-tuples to use as options for this field. If this is given - Django's admin will use a select box instead of the standard text field and will limit options to those given.
get(**kwargs)
==
Many-to-many relationship to self
choices
6. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-one relationship
intermediate models
MultipleObjectsReturned
many-to-many relationship
7. 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.
default
update()
through argument
id field
8. Lookup type that returns results less than or equal to a given value.
exists()
lte
save()
choices tuple
9. Keyword shortcut for looking up an object by primary key.
Meta class
pk
Q(question__istartswith='What')
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
10. 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.
|
values(*fields)
exact
save()
11. If this option is True - the field is allowed to be blank. Default is False.
blank
iregex
day
Q(question__istartswith='What')
12. 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.
primary_key
search
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Multi-table inheritance
13. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
exclude(**kwargs)
delete()
distinct()
all()
14. The default for this is the name of the child class followed by '_set'.
get_or_create(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
select_related()
reverse name
15. Lookup type that yields a case-insensitive match.
iexact
Manager methods
pickling
get(**kwargs)
16. 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.
month
get(**kwargs)
ManyToManyField
all()
17. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
ForeignKey
all()
exclude(**kwargs)
in_bulk(id_list)
18. 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.
only(*fields)
class type
primary_key
get_absolute_url()
19. A convenience method for constructing an object and saving it all in one step.
filter(**kwargs)
create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
get_or_create(**kwargs)
20. Lookup type that returns results with a case-sensitive start sequence.
pk
primary_key
startswith
ordered
21. a QuerySet can be sliced - using Python's array-slicing syntax.
filter(**kwargs)
iexact
slicing
primary_key
22. 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.
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.
help_text
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
add()
DoesNotExist
24. Returns the object matching the given lookup parameters
Model metadata
F()
month
get(**kwargs)
25. Lookup type that returns results in a given list.
in
filter(**kwargs)
Entry.objects.filter(id__gt=4)
id field
26. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
27. A convenience method for looking up an object with the given kwargs - creating one if necessary.
all()
Proxy model
create(**kwargs)
get_or_create(**kwargs)
28. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
ManyToManyField
search
aggregate(args - *kwargs)
29. 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
F()
Model metadata
reverse name
get(**kwargs)
30. Performs an SQL update query for the specified fields - and returns the number of rows affected. This method is applied instantly and the only restriction on the QuerySet that is updated is that it can only update columns in the model's main table. F
through argument
update(**kwargs)
Q(question__istartswith='What')
only(*fields)
31. Lookup type that finds a case-insensitive regular expression match.
lt
id field
month
iregex
32. 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.
day
__unicode__()
Multi-table inheritance
month
33. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
help_text
Manager methods
week_day
related_name
34. 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.
ordered
get_or_create(**kwargs)
values(*fields)
reverse()
35. 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.
gte
OneToOneField
many-to-one relationship
istartswith
36. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
values_list(*fields)
exists()
count()
37. This represents a collection of objects from your database. It can have zero - one or many filters.
update(**kwargs)
QuerySet
filter(**kwargs)
dates(field - kind - order='ASC')
38. Conjuntion operator for Q objects.
Custom model methods
all()
&
QuerySet
39. Lookup type that tests for inclusion in a case-sensitive fashion.
many-to-one relationship
contains
get_absolute_url()
one-to-one relationship
40. These methods are intended to do "table-wide" things.
Manager methods
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Entry.objects.filter(id__in=[1 - 3 - 4])
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
41. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
42. Disjunction operator for Q objects.
|
select_related()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
ordered
43. (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.
in
Restrictions on field names
distinct()
choices tuple
44. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
update()
none()
model
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
45. This query finds all entries with an id greater than 4.
Q(question__istartswith='What')
Entry.objects.filter(id__gt=4)
delete()
class attributes
46. This query deletes all Entry objects with a pub_date year of 2005.
regex
related_name
update()
Entry.objects.filter(pub_date__year=2005).delete()
47. Lookup type that returns results greater than a given value.
ordered
gt
none()
year
48. 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
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
model
through argument
lt
49. Fields are specified by these
class attributes
istartswith
Entry.objects.filter(pub_date__year=2005).delete()
|
50. 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
save()
intermediate models
Custom model methods
Model metadata