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. Can be used to remove all many-to-many relationships for an instance
none()
clear() method
pickling
gte
2. 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.
delete()
exclude(**kwargs)
through argument
search
3. This method is for controlling which database the QuerySet will be evaluated against if you are using more than one database. The only argument this method takes is the alias of a database - as defined in DATABASES.
range
using(alias)
get_absolute_url()
year
4. Lookup type that yields a case-insensitive match.
in
filter(**kwargs)
iexact
Entry.objects.filter(id__gt=4)
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.
in_bulk(id_list)
exists()
unique
many-to-many relationship
6. A convenience method for looking up an object with the given kwargs - creating one if necessary.
filter chaining
get_or_create(**kwargs)
reverse name
blank
7. a QuerySet can be sliced - using Python's array-slicing syntax.
Q()
slicing
Field lookups
filter(**kwargs)
8. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
delete()
~
delete()
distinct()
9. Lookup type that returns results that fall into an inclusive date range.
one-to-one relationship
Manager
range
exclude(**kwargs)
10. 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
clear() method
contains
iendswith
11. 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.
many-to-one relationship
Entry.objects.filter(id__gt=4)
month
null
12. 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.
get(**kwargs)
iregex
iendswith
startswith
13. Lookup type that returns results with a case-sensitive end sequence.
blank
ordered
endswith
Model metadata
14. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
Q()
save()
year
gte
15. This represents a collection of objects from your database. It can have zero - one or many filters.
exclude(**kwargs)
QuerySet
MultipleObjectsReturned
update()
16. This query finds all entries with an id greater than 4.
endswith
get_absolute_url()
Entry.objects.filter(pub_date__year=2005).delete()
Entry.objects.filter(id__gt=4)
17. If this option is True - the field is allowed to be blank. Default is False.
values(*fields)
ordered
blank
slicing
18. Lookup type that finds a case-insensitive regular expression match.
Multi-table inheritance
Many-to-many relationship through an intermediate model
==
iregex
19. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
ordered
many-to-many relationship
istartswith
20. 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
Model metadata
search
choices
class type
21. (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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Restrictions on field names
related_name
model
22. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
Abstract base class
update()
startswith
23. Returns the most recent object in the table - by date - using the field_name provided as the date field.
one-to-one relationship
Model metadata
latest(field_name=None)
Manager
24. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
Meta class
many-to-many relationship
values(*fields)
25. Negation operator for Q objects.
all()
~
only(*fields)
Q()
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.
only(*fields)
exact
iteration
default
27. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
filter(**kwargs)
db
update(**kwargs)
28. If True - this field is the primary key for the model.
delete()
primary_key
default
gt
29. 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.
iregex
startswith
ManyToManyField
delete()
30. 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.
ManyToManyField
endswith
pickling
all()
31. This query finds all entries with an id in the list [1 - 3 - 4]
choices
week_day
using(alias)
Entry.objects.filter(id__in=[1 - 3 - 4])
32. Lookup type for date/datetime fields that finds an exact day match.
none()
day
ManyToManyField
lte
33. The database that will be used if this query is executed now
get_absolute_url()
MultipleObjectsReturned
default
db
34. Lookup type that returns results greater than or equal to a given value.
Manager methods
Meta class
QuerySet
gte
35. Lookup type that finds a case-sensitive regular expression match.
Field lookups
regex
filter
using(alias)
36. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
primary_key
only(*fields)
order_by(*fields)
37. When to run syncdb
when you add new apps to INSTALLED_APPS
Entry.objects.filter(id__in=[1 - 3 - 4])
iendswith
Many-to-many relationship to self
38. 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
Model metadata
exclude(**kwargs)
only(*fields)
iterator()
39. These methods are intended to do "table-wide" things.
regex
when you add new apps to INSTALLED_APPS
Manager methods
MultipleObjectsReturned
40. 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
Custom model methods
DoesNotExist
filter(**kwargs)
41. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
ManyToManyField
F()
many-to-one relationship
42. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
defer(*fields)
Q()
endswith
isnull
43. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
through argument
id field
search
44. This model method is used for updating a ManyToManyField.
add()
in
OneToOneField
Custom model methods
45. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
distinct()
year
blank
primary_key
46. Manager method used to retrieve every object in a model.
create(**kwargs)
all()
MultipleObjectsReturned
filter(**kwargs)
47. 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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
add()
slicing
default
48. 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
isnull
when you add new apps to INSTALLED_APPS
lt
49. Fields are specified by these
F()
class attributes
Meta class
default
50. Returns the object matching the given lookup parameters
filter
add()
get(**kwargs)
intermediate models