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. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
filter(**kwargs)
using(alias)
Entry.objects.filter(pub_date__year=2005).delete()
related_name
2. This query finds all entries with an id greater than 4.
all()
MultipleObjectsReturned
iexact
Entry.objects.filter(id__gt=4)
3. (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.
get_absolute_url()
exclude(**kwargs)
Restrictions on field names
class attributes
4. Returns the most recent object in the table - by date - using the field_name provided as the date field.
lt
latest(field_name=None)
ordered
get_absolute_url()
5. 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.
isnull
lt
OneToOneField
Q()
6. 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.
search
Q(question__istartswith='What')
using(alias)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
7. Can be used to remove all many-to-many relationships for an instance
reverse()
ForeignKey
related_name
clear() method
8. This model method is used for updating a ManyToManyField.
week_day
add()
year
filter(**kwargs)
9. 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.
iteration
isnull
exclude(**kwargs)
reverse()
10. 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()
evaluation
filter(**kwargs)
~
save()
11. Lookup type that returns results with a case-insensitive start sequence.
isnull
Entry.objects.filter(id__gt=4)
istartswith
filter(**kwargs)
12. 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.
null
many-to-many relationship
update()
Field lookups
13. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
when you add new apps to INSTALLED_APPS
==
dates(field - kind - order='ASC')
Many-to-many relationship through an intermediate model
14. This method immediately deletes the object and has no return value.
choices tuple
Custom model methods
update()
delete()
15. Lookup type that tests for inclusion in a case-sensitive fashion.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
update(**kwargs)
filter chaining
contains
16. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
one-to-one relationship
many-to-one relationship
related_name
ordered
17. 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
clear() method
Proxy model
update(**kwargs)
18. Disjunction operator for Q objects.
filter(**kwargs)
range
|
Many-to-many relationship through an intermediate model
19. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
update(**kwargs)
filter chaining
null
20. 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()
choices
distinct()
class attributes
21. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
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
many-to-one relationship
annotate(args - *kwargs)
filter(**kwargs)
Manager
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
exact
Abstract base class
startswith
latest(field_name=None)
24. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
exact
Field lookups
delete()
Abstract base class
25. A convenience method for constructing an object and saving it all in one step.
filter(**kwargs)
create(**kwargs)
reverse()
intermediate models
26. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
startswith
update()
QuerySet
27. 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
28. 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.
many-to-one relationship
choices tuple
create(**kwargs)
ordered
29. Fields are specified by these
class attributes
create(**kwargs)
day
get_or_create(**kwargs)
30. 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.
day
~
choices
get_or_create(**kwargs)
31. Manager method used to retrieve every object in a model.
aggregate(args - *kwargs)
defer(*fields)
all()
Model metadata
32. This model method saves a model instance to the database. This method has no return value.
year
save()
OneToOneField
filter(**kwargs)
33. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Manager
month
dates(field - kind - order='ASC')
choices
34. Returns the object matching the given lookup parameters
get_or_create(**kwargs)
get(**kwargs)
Entry.objects.filter(id__gt=4)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
35. This query deletes all Entry objects with a pub_date year of 2005.
Proxy model
null
delete()
Entry.objects.filter(pub_date__year=2005).delete()
36. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
Entry.objects.filter(id__in=[1 - 3 - 4])
model
save()
get_or_create(**kwargs)
37. 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()
range
reverse()
slicing
38. A convenience method for looking up an object with the given kwargs - creating one if necessary.
model
reverse name
get_or_create(**kwargs)
OneToOneField
39. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
filter(**kwargs)
QuerySet
Entry.objects.filter(id__in=[1 - 3 - 4])
distinct()
40. 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.
save()
select_related()
iterator()
Many-to-many relationship through an intermediate model
41. 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
filter chaining
select_related()
class attributes
save()
42. 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.
search
contains
iteration
values_list(*fields)
43. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
Many-to-many relationship through an intermediate model
isnull
many-to-one relationship
Entry.objects.filter(id__gt=4)
44. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
DoesNotExist
Q()
QuerySet
values(*fields)
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
only(*fields)
istartswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
isnull
46. This query finds all entries with an id in the list [1 - 3 - 4]
iregex
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Entry.objects.filter(id__in=[1 - 3 - 4])
gte
47. 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(**kwargs)
get(**kwargs)
pickling
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
48. To activate your models
Many-to-many relationship to self
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
get_absolute_url()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
49. Returns a new QuerySet containing objects that match the given lookup parameters.
ManyToManyField
filter(**kwargs)
choices
get(**kwargs)
50. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
many-to-one relationship
null
dates(field - kind - order='ASC')