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. Lookup type that returns results less than or equal to a given value.
isnull
year
lte
class type
2. These add custom "row-level" functionality to your objects. These act on a particular model instance.
model
Custom model methods
~
save()
3. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
model
ordered
MultipleObjectsReturned
default
4. 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
5. Used to get a QuerySet for a model. This is called 'objects' by default.
relationship spanning
Manager
DoesNotExist
exact
6. Returns the object matching the given lookup parameters
iteration
|
relationship spanning
get(**kwargs)
7. 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.
choices
related_name
Model metadata
~
8. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
through argument
Model metadata
OneToOneField
iteration
9. When to run syncdb
Q()
id field
when you add new apps to INSTALLED_APPS
unique
10. 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.
Q()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Many-to-many relationship through an intermediate model
reverse()
11. 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
12. 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.
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
clear() method
isnull
13. 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()
week_day
get(**kwargs)
F()
14. Can be used to remove all many-to-many relationships for an instance
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
clear() method
ManyToManyField
Manager
15. If this option is True - Django will store empty values as NULL in the database. Default is False.
model
null
Field lookups
regex
16. 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)
Entry.objects.filter(id__in=[1 - 3 - 4])
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Model metadata
relationship spanning
17. 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)
__unicode__()
order_by(*fields)
choices
18. Conjuntion operator for Q objects.
reverse name
filter chaining
lte
&
19. Returns a new QuerySet containing objects that match the given lookup parameters.
Q(question__istartswith='What')
filter(**kwargs)
using(alias)
count()
20. Fields are specified by these
class attributes
filter chaining
delete()
update()
21. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
select_related()
exact
week_day
22. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
Many-to-many relationship through an intermediate model
choices
model
intermediate models
23. 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.
search
Field lookups
filter
dates(field - kind - order='ASC')
24. 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.
in
istartswith
exact
ForeignKey
25. This query finds all entries with an id greater than 4.
filter chaining
Entry.objects.filter(id__gt=4)
all()
lt
26. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
contains
reverse()
filter chaining
using(alias)
27. This gives your model metadata.
Meta class
iexact
class attributes
get(**kwargs)
28. Lookup type that yields a case-insensitive match.
iexact
through argument
none()
related_name
29. 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.
exact
&
get(**kwargs)
QuerySet
30. This query deletes all Entry objects with a pub_date year of 2005.
class type
distinct()
Entry.objects.filter(pub_date__year=2005).delete()
Many-to-many relationship through an intermediate model
31. Manager method used to retrieve every object in a model.
QuerySet
all()
__unicode__()
delete()
32. This model method saves a model instance to the database. This method has no return value.
Q(question__istartswith='What')
default
save()
many-to-many relationship
33. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
default
class type
lt
filter(**kwargs)
34. 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.
values_list(*fields)
using(alias)
lt
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
35. Lookup type that returns results that fall into an inclusive date range.
filter chaining
add()
update()
range
36. 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.
Multi-table inheritance
iendswith
clear() method
MultipleObjectsReturned
37. Lookup type that returns results in a given list.
in
endswith
unique
Meta class
38. (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.
&
Many-to-many relationship to self
Restrictions on field names
latest(field_name=None)
39. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
iterator()
&
QuerySet
year
40. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
exact
reverse()
search
one-to-one relationship
41. To activate your models
DoesNotExist
get(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
slicing
42. 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
|
lte
annotate(args - *kwargs)
iterator()
43. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
through argument
class type
ordered
44. 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.
latest(field_name=None)
id field
get_absolute_url()
Entry.objects.filter(pub_date__year=2005).delete()
45. 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
search
Proxy model
aggregate(args - *kwargs)
when you add new apps to INSTALLED_APPS
46. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
save()
month
class type
many-to-many relationship
47. 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
~
latest(field_name=None)
contains
defer(*fields)
48. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
iteration
regex
defer(*fields)
49. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Meta class
lt
related_name
MultipleObjectsReturned
50. Lookup type that tests for inclusion in a case-sensitive fashion.
Many-to-many relationship to self
none()
contains
create(**kwargs)