SUBJECTS
|
BROWSE
|
CAREER CENTER
|
POPULAR
|
JOIN
|
LOGIN
Business Skills
|
Soft Skills
|
Basic Literacy
|
Certifications
About
|
Help
|
Privacy
|
Terms
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. 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.
get_or_create(**kwargs)
choices tuple
in_bulk(id_list)
Abstract base class
2. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
day
distinct()
add()
isnull
3. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iregex
many-to-many relationship
~
filter
4. Conjuntion operator for Q objects.
model
month
ordered
&
5. Lookup type that returns results less than or equal to a given value.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
lte
slicing
one-to-one relationship
6. Used to get a QuerySet for a model. This is called 'objects' by default.
when you add new apps to INSTALLED_APPS
Manager
get_absolute_url()
get(**kwargs)
7. 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.
get_absolute_url()
MultipleObjectsReturned
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
QuerySet
8. 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
latest(field_name=None)
ordered
relationship spanning
9. Lookup type that yields a case-insensitive match.
choices tuple
iexact
Manager
OneToOneField
10. 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.
&
ManyToManyField
year
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
11. Returns the most recent object in the table - by date - using the field_name provided as the date field.
istartswith
update()
latest(field_name=None)
week_day
12. 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.
order_by(*fields)
Abstract base class
Many-to-many relationship through an intermediate model
Model metadata
13. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
select_related()
Q(question__istartswith='What')
year
14. Lookup type that returns results greater than a given value.
reverse()
primary_key
gt
&
15. 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.
none()
choices tuple
year
many-to-one relationship
16. This gives your model metadata.
Q(question__istartswith='What')
intermediate models
Entry.objects.filter(id__gt=4)
Meta class
17. Fields are specified by these
through argument
class attributes
Custom model methods
relationship spanning
18. This model method saves a model instance to the database. This method has no return value.
intermediate models
iteration
none()
save()
19. 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()
Meta class
latest(field_name=None)
aggregate(args - *kwargs)
20. Lookup type that returns results less than a given value.
regex
db
lt
endswith
21. This model method is used for updating a ManyToManyField.
add()
year
many-to-one relationship
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
22. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
exists()
iregex
count()
23. 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
iregex
Many-to-many relationship through an intermediate model
in_bulk(id_list)
Abstract base class
24. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
ManyToManyField
default
25. 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.
class attributes
ordered
exact
delete()
26. 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)
values_list(*fields)
endswith
Model metadata
lte
27. Exception raised by get(**kwargs) if no items match the query.
gt
DoesNotExist
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
filter
28. 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
annotate(args - *kwargs)
all()
iterator()
save()
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
filter chaining
contains
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
F()
30. Lookup type that returns results with a case-insensitive start sequence.
Entry.objects.filter(pub_date__range=(start_date - end_date))
istartswith
OneToOneField
year
31. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
order_by(*fields)
iterator()
Manager
32. This query uses an F object to increment the pingback count for every entry in the blog.
33. 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
F()
ForeignKey
range
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)
many-to-one relationship
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
primary_key
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.
OneToOneField
create(**kwargs)
model
help_text
36. 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()
get_or_create(**kwargs)
Restrictions on field names
regex
37. 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
through argument
values(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
ForeignKey
38. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.
many-to-many relationship
Many-to-many relationship to self
range
__unicode__()
39. Lookup type that finds a case-insensitive regular expression match.
delete()
gte
one-to-one relationship
iregex
40. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
slicing
id field
primary_key
month
41. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
choices tuple
|
OneToOneField
42. 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
Meta class
update(**kwargs)
filter chaining
43. Lookup type that finds a case-sensitive regular expression match.
regex
add()
filter chaining
Restrictions on field names
44. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
Q()
save()
many-to-many relationship
iteration
45. Exception raised by get(**kwargs) if more than one item matches the query.
day
exclude(**kwargs)
&
MultipleObjectsReturned
46. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()
startswith
Entry.objects.filter(pub_date__range=(start_date - end_date))
iterator()
evaluation
47. Lookup type that returns results with a case-sensitive start sequence.
gt
startswith
Q(question__istartswith='What')
__unicode__()
48. Returns a new QuerySet containing objects that match the given lookup parameters.
day
count()
filter(**kwargs)
unique
49. Lookup type that returns results with a case-insensitive end sequence.
iendswith
null
Custom model methods
~
50. 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
update()
reverse()
aggregate(args - *kwargs)
relationship spanning