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. 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.
latest(field_name=None)
lte
order_by(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
2. This gives your model metadata.
Meta class
Custom model methods
__unicode__()
filter(**kwargs)
3. Keyword shortcut for looking up an object by primary key.
pk
reverse name
iexact
__unicode__()
4. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
contains
exclude(**kwargs)
delete()
startswith
5. 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.
aggregate(args - *kwargs)
|
in_bulk(id_list)
iexact
6. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
update()
Custom model methods
|
F()
7. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
primary_key
Q(question__istartswith='What')
values(*fields)
relationship spanning
8. 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
iterator()
Multi-table inheritance
filter
search
9. 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.
model
values_list(*fields)
MultipleObjectsReturned
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
10. The database that will be used if this query is executed now
~
db
using(alias)
annotate(args - *kwargs)
11. Exception raised by get(**kwargs) if more than one item matches the query.
model
one-to-one relationship
values(*fields)
MultipleObjectsReturned
12. This query finds all entries between a start date of start_date and an end date of end_date.
gt
order_by(*fields)
add()
Entry.objects.filter(pub_date__range=(start_date - end_date))
13. 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.
F()
Entry.objects.filter(id__in=[1 - 3 - 4])
choices
~
14. If True - this field is the primary key for the model.
primary_key
choices
DoesNotExist
month
15. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
gte
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
db
month
16. Lookup type that finds a case-sensitive regular expression match.
reverse name
lt
regex
annotate(args - *kwargs)
17. 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.
when you add new apps to INSTALLED_APPS
search
iexact
gte
18. Fields are specified by these
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
related_name
class attributes
values_list(*fields)
19. Returns the object matching the given lookup parameters
annotate(args - *kwargs)
intermediate models
get(**kwargs)
values(*fields)
20. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
update()
slicing
Abstract base class
ordered
21. 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.
add()
filter(**kwargs)
ForeignKey
exact
22. 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.
exact
ManyToManyField
Manager methods
get_or_create(**kwargs)
23. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
distinct()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
get(**kwargs)
24. A convenience method for constructing an object and saving it all in one step.
dates(field - kind - order='ASC')
create(**kwargs)
db
pickling
25. 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.
Multi-table inheritance
reverse()
class attributes
lte
26. 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.
all()
none()
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.
27. Negation operator for Q objects.
using(alias)
add()
~
one-to-one relationship
28. Lookup type that returns results in a given list.
in
==
ordered
update(**kwargs)
29. 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.
&
when you add new apps to INSTALLED_APPS
get_absolute_url()
range
30. 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
lt
Abstract base class
only(*fields)
model
31. Returns the most recent object in the table - by date - using the field_name provided as the date field.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
latest(field_name=None)
istartswith
32. 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.
help_text
only(*fields)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Many-to-many relationship through an intermediate model
33. Lookup type that finds a case-insensitive regular expression match.
blank
select_related()
Abstract base class
iregex
34. a QuerySet can be sliced - using Python's array-slicing syntax.
in_bulk(id_list)
slicing
get_or_create(**kwargs)
Restrictions on field names
35. Lookup type that returns results with a case-sensitive end sequence.
delete()
endswith
iregex
Entry.objects.filter(pub_date__year=2005).delete()
36. 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
intermediate models
filter(**kwargs)
F()
==
37. This model method is used for updating a ManyToManyField.
Manager
lte
add()
model
38. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
annotate(args - *kwargs)
Entry.objects.filter(id__gt=4)
values(*fields)
gte
39. Lookup type that returns results less than or equal to a given value.
all()
class type
count()
lte
40. 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()
filter chaining
Entry.objects.filter(pub_date__year=2005).delete()
lt
41. This method immediately deletes the object and has no return value.
Field lookups
when you add new apps to INSTALLED_APPS
delete()
choices
42. When to run syncdb
default
endswith
when you add new apps to INSTALLED_APPS
exists()
43. Lookup type that returns results with a case-insensitive start sequence.
primary_key
istartswith
range
week_day
44. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
many-to-many relationship
Manager
count()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
45. Lookup type that returns results greater than or equal to a given value.
Restrictions on field names
get(**kwargs)
slicing
gte
46. 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
47. If this option is True - Django will store empty values as NULL in the database. Default is False.
many-to-one relationship
null
intermediate models
unique
48. The default for this is the name of the child class followed by '_set'.
gt
many-to-one relationship
reverse name
Q(question__istartswith='What')
49. 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.
evaluation
help_text
Entry.objects.filter(id__in=[1 - 3 - 4])
regex
50. Lookup type that returns results with a case-sensitive start sequence.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
DoesNotExist
select_related()
startswith