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 takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
Restrictions on field names
dates(field - kind - order='ASC')
lte
2. 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.
Many-to-many relationship to self
search
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
latest(field_name=None)
3. This represents a collection of objects from your database. It can have zero - one or many filters.
relationship spanning
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
DoesNotExist
QuerySet
4. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
Q(question__istartswith='What')
ForeignKey
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
5. 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()
ForeignKey
Multi-table inheritance
delete()
6. 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.
in_bulk(id_list)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
defer(*fields)
exact
7. If this option is True - the field is allowed to be blank. Default is False.
count()
blank
aggregate(args - *kwargs)
update(**kwargs)
8. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
blank
F()
relationship spanning
9. Lookup type that returns results less than or equal to a given value.
Meta class
istartswith
lte
many-to-many relationship
10. Lookup type that finds a case-sensitive regular expression match.
regex
search
primary_key
ForeignKey
11. 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.
endswith
Proxy model
Q(question__istartswith='What')
delete()
12. 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
lt
defer(*fields)
|
Manager
13. Lookup type that finds a case-insensitive regular expression match.
iregex
blank
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
slicing
14. Used to get a QuerySet for a model. This is called 'objects' by default.
contains
ForeignKey
Manager
Restrictions on field names
15. 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
~
lte
order_by(*fields)
16. 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.
primary_key
iterator()
many-to-one relationship
week_day
17. 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.
iterator()
aggregate(args - *kwargs)
order_by(*fields)
get_absolute_url()
18. Negation operator for Q objects.
annotate(args - *kwargs)
delete()
delete()
~
19. When to run syncdb
unique
week_day
defer(*fields)
when you add new apps to INSTALLED_APPS
20. 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.
in_bulk(id_list)
filter chaining
relationship spanning
Many-to-many relationship through an intermediate model
21. Fields are specified by these
Entry.objects.filter(pub_date__range=(start_date - end_date))
search
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
class attributes
22. 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.
select_related()
Multi-table inheritance
Model metadata
ForeignKey
23. 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
iregex
reverse()
defer(*fields)
24. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
25. Lookup type that returns results less than a given value.
|
==
clear() method
lt
26. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
OneToOneField
model
isnull
DoesNotExist
27. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
Q(question__istartswith='What')
gte
aggregate(args - *kwargs)
28. 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
lt
null
update(**kwargs)
all()
29. Lookup type for date/datetime fields that finds an exact day match.
day
&
primary_key
QuerySet
30. Can be used to remove all many-to-many relationships for an instance
defer(*fields)
create(**kwargs)
id field
clear() method
31. This is a criterion that narrow down a QuerySet based on given parameters.
all()
filter
~
year
32. Returns the object matching the given lookup parameters
get(**kwargs)
ForeignKey
range
relationship spanning
33. Returns the most recent object in the table - by date - using the field_name provided as the date field.
==
get(**kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
latest(field_name=None)
34. 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.
order_by(*fields)
pk
Multi-table inheritance
iterator()
35. Returns a new QuerySet containing objects that match the given lookup parameters.
update(**kwargs)
filter(**kwargs)
Abstract base class
model
36. 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.
all()
Restrictions on field names
ManyToManyField
|
37. Disjunction operator for Q objects.
|
add()
Abstract base class
model
38. 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
Multi-table inheritance
Abstract base class
ForeignKey
add()
39. This model method is used for updating a ManyToManyField.
Model metadata
add()
get_or_create(**kwargs)
get_absolute_url()
40. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
using(alias)
help_text
when you add new apps to INSTALLED_APPS
41. 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
Proxy model
month
gte
42. 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()
create(**kwargs)
filter(**kwargs)
values(*fields)
43. 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.
in
ManyToManyField
lt
get_absolute_url()
44. 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
primary_key
through argument
exists()
clear() method
45. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary
|
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
only(*fields)
many-to-one relationship
46. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
iexact
F()
week_day
47. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
model
many-to-one relationship
all()
48. Lookup type that returns results with a case-sensitive end sequence.
endswith
regex
relationship spanning
Restrictions on field names
49. 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
update(**kwargs)
annotate(args - *kwargs)
dates(field - kind - order='ASC')
related_name
50. 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
intermediate models
null
db