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 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.
Field lookups
blank
exact
Meta class
2. 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.
dates(field - kind - order='ASC')
istartswith
reverse name
values_list(*fields)
3. This method immediately deletes the object and has no return value.
ManyToManyField
delete()
exact
through argument
4. 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
many-to-one relationship
many-to-many relationship
slicing
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.
evaluation
clear() method
Field lookups
in_bulk(id_list)
6. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iterator()
many-to-many relationship
clear() method
slicing
7. 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.
Abstract base class
Restrictions on field names
Multi-table inheritance
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
8. 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)
Meta class
Model metadata
db
9. A convenience method for looking up an object with the given kwargs - creating one if necessary.
filter
help_text
get_or_create(**kwargs)
get_absolute_url()
10. Returns a new QuerySet containing objects that match the given lookup parameters.
slicing
Proxy model
Manager
filter(**kwargs)
11. This query finds all entries with an id greater than 4.
clear() method
Restrictions on field names
choices tuple
Entry.objects.filter(id__gt=4)
12. Lookup type that returns results less than or equal to a given value.
choices
lte
isnull
MultipleObjectsReturned
13. To activate your models
gte
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Field lookups
Manager
14. 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.
unique
ManyToManyField
many-to-one relationship
one-to-one relationship
15. 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.
related_name
when you add new apps to INSTALLED_APPS
relationship spanning
default
16. Lookup type for date/datetime fields that finds an exact day match.
day
annotate(args - *kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
class attributes
17. Lookup type that returns results less than a given value.
lt
get(**kwargs)
related_name
ManyToManyField
18. Lookup type that returns results greater than a given value.
gt
exists()
distinct()
aggregate(args - *kwargs)
19. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
order_by(*fields)
month
slicing
20. This query uses an F object to increment the pingback count for every entry in the blog.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
21. This gives your model metadata.
save()
Entry.objects.filter(id__gt=4)
Entry.objects.filter(id__in=[1 - 3 - 4])
Meta class
22. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
get_or_create(**kwargs)
only(*fields)
slicing
23. Returns the most recent object in the table - by date - using the field_name provided as the date field.
search
latest(field_name=None)
contains
Q()
24. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
aggregate(args - *kwargs)
unique
latest(field_name=None)
25. 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.
OneToOneField
Field lookups
ManyToManyField
istartswith
26. 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 to self
many-to-one relationship
&
filter chaining
27. Returns the object matching the given lookup parameters
&
one-to-one relationship
Abstract base class
get(**kwargs)
28. This query finds all entries with an id in the list [1 - 3 - 4]
MultipleObjectsReturned
Entry.objects.filter(id__in=[1 - 3 - 4])
class type
delete()
29. 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
Abstract base class
Multi-table inheritance
default
update()
30. 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
only(*fields)
order_by(*fields)
update()
iterator()
31. 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.
id field
order_by(*fields)
annotate(args - *kwargs)
choices
32. Used to get a QuerySet for a model. This is called 'objects' by default.
dates(field - kind - order='ASC')
DoesNotExist
all()
Manager
33. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
get_or_create(**kwargs)
OneToOneField
related_name
Manager methods
34. If you pickle a QuerySet - this will force all the results to be loaded into memory prior to pickling. When you unpickle a QuerySet - it contains the results at the moment it was pickled - rather than the results that are currently in the database.
filter
values(*fields)
one-to-one relationship
pickling
35. 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()
many-to-many relationship
range
DoesNotExist
evaluation
36. Lookup type that returns results in a given list.
search
in
pickling
relationship spanning
37. Lookup type that returns results with a case-insensitive start sequence.
istartswith
all()
choices tuple
exclude(**kwargs)
38. 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()
Multi-table inheritance
gt
aggregate(args - *kwargs)
39. This field is added automatically - but this behavior can be overridden
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
reverse name
Abstract base class
id field
40. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
regex
gt
filter(**kwargs)
41. If this option is True - Django will store empty values as NULL in the database. Default is False.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
select_related()
null
defer(*fields)
42. Lookup type for date/datetime fields that finds a 'day of the week' match.
when you add new apps to INSTALLED_APPS
week_day
&
Many-to-many relationship through an intermediate model
43. 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
QuerySet
endswith
annotate(args - *kwargs)
select_related()
44. Lookup type that finds a case-sensitive regular expression match.
db
regex
month
in_bulk(id_list)
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
|
Many-to-many relationship through an intermediate model
choices tuple
only(*fields)
46. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
startswith
exclude(**kwargs)
search
47. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
48. Disjunction operator for Q objects.
|
many-to-many relationship
update(**kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
49. This query deletes all Entry objects with a pub_date year of 2005.
isnull
Entry.objects.filter(pub_date__year=2005).delete()
many-to-many relationship
delete()
50. 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.
~
class attributes
reverse()
update()