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 yields a case-insensitive match.
lte
iexact
filter(**kwargs)
gte
2. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
~
model
dates(field - kind - order='ASC')
3. 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.
ordered
Multi-table inheritance
only(*fields)
annotate(args - *kwargs)
4. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
Multi-table inheritance
search
year
many-to-one relationship
5. Returns an EmptyQuerySet -- a QuerySet that always evaluates to an empty list. This can be used in cases where you know that you should return an empty result set and your caller is expecting a QuerySet object (instead of returning an empty list - fo
annotate(args - *kwargs)
none()
exact
iregex
6. 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.
regex
values_list(*fields)
default
Entry.objects.filter(pub_date__year=2005).delete()
7. 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.
intermediate models
F()
&
choices tuple
8. This query finds all entries with an id greater than 4.
filter chaining
update()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(id__gt=4)
9. The default for this is the name of the child class followed by '_set'.
DoesNotExist
reverse name
~
count()
10. 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.
db
delete()
get(**kwargs)
Entry.objects.filter(id__in=[1 - 3 - 4])
11. Lookup type that finds a case-sensitive regular expression match.
regex
OneToOneField
all()
contains
12. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
all()
distinct()
lte
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
13. Lookup type that returns results greater than or equal to a given value.
values_list(*fields)
class type
gte
evaluation
14. The database that will be used if this query is executed now
iexact
db
|
default
15. 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
unique
Proxy model
filter chaining
OneToOneField
16. To activate your models
in_bulk(id_list)
Custom model methods
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
DoesNotExist
17. Conjuntion operator for Q objects.
==
latest(field_name=None)
&
Entry.objects.filter(pub_date__year=2005).delete()
18. This gives your model metadata.
Meta class
Model metadata
model
update()
19. Exception raised by get(**kwargs) if more than one item matches the query.
&
Q()
MultipleObjectsReturned
exact
20. 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
Entry.objects.filter(id__in=[1 - 3 - 4])
iterator()
filter
values(*fields)
21. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
select_related()
Entry.objects.filter(pub_date__year=2005).delete()
evaluation
regex
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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Manager
annotate(args - *kwargs)
__unicode__()
23. This represents a collection of objects from your database. It can have zero - one or many filters.
order_by(*fields)
unique
QuerySet
gte
24. Lookup type that returns results with a case-insensitive end sequence.
model
annotate(args - *kwargs)
one-to-one relationship
iendswith
25. Fields are specified by these
iterator()
OneToOneField
choices
class attributes
26. 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.
delete()
exact
in
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
27. This query deletes all Entry objects with a pub_date year of 2005.
when you add new apps to INSTALLED_APPS
pk
Entry.objects.filter(pub_date__year=2005).delete()
order_by(*fields)
28. Lookup type for date/datetime fields that finds a 'day of the week' match.
defer(*fields)
values_list(*fields)
week_day
iterator()
29. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
all()
filter(**kwargs)
==
one-to-one relationship
30. These add custom "row-level" functionality to your objects. These act on a particular model instance.
&
Custom model methods
null
add()
31. 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.
Many-to-many relationship through an intermediate model
many-to-many relationship
values(*fields)
update()
32. 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.
Custom model methods
Many-to-many relationship to self
search
count()
33. (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.
add()
all()
null
Restrictions on field names
34. Lookup type that tests for inclusion in a case-sensitive fashion.
add()
range
default
contains
35. 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
order_by(*fields)
iexact
in
class type
36. 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.
range
ordered
Meta class
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
37. 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.
lte
Many-to-many relationship to self
exact
filter(**kwargs)
38. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
contains
through argument
filter(**kwargs)
many-to-one relationship
39. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
update()
many-to-many relationship
week_day
relationship spanning
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()
Restrictions on field names
none()
in_bulk(id_list)
41. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__gt=4)
primary_key
range
Entry.objects.filter(id__in=[1 - 3 - 4])
42. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
save()
Q()
iendswith
Field lookups
43. 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
relationship spanning
search
in
Manager methods
44. 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
exists()
intermediate models
get(**kwargs)
ordered
45. Lookup type that returns results greater than a given value.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
clear() method
Entry.objects.filter(pub_date__range=(start_date - end_date))
gt
46. Lookup type that returns results less than a given value.
in_bulk(id_list)
exclude(**kwargs)
~
lt
47. Disjunction operator for Q objects.
iexact
Entry.objects.filter(id__gt=4)
month
|
48. Lookup type for date/datetime fields that finds an exact day match.
day
aggregate(args - *kwargs)
Q(question__istartswith='What')
reverse()
49. This query finds all entries between a start date of start_date and an end date of end_date.
OneToOneField
search
Q(question__istartswith='What')
Entry.objects.filter(pub_date__range=(start_date - end_date))
50. Used to get a QuerySet for a model. This is called 'objects' by default.
reverse()
iregex
day
Manager