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. This query finds all entries with an id in the list [1 - 3 - 4]
DoesNotExist
add()
Entry.objects.filter(id__in=[1 - 3 - 4])
count()
2. This field is added automatically - but this behavior can be overridden
Manager methods
year
id field
reverse name
3. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
month
Many-to-many relationship to self
Abstract base class
count()
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
Entry.objects.filter(pub_date__range=(start_date - end_date))
Proxy model
Restrictions on field names
5. This is a criterion that narrow down a QuerySet based on given parameters.
clear() method
aggregate(args - *kwargs)
exact
filter
6. This query finds all entries with an id greater than 4.
evaluation
Entry.objects.filter(id__gt=4)
search
dates(field - kind - order='ASC')
7. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)
model
&
Model metadata
filter chaining
8. Lookup type that returns results with a case-sensitive end sequence.
Proxy model
filter(**kwargs)
endswith
Manager methods
9. Returns a DateQuerySet -- a QuerySet that evaluates to a list of datetime.datetime objects representing all available dates of a particular kind within the contents of the QuerySet.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
10. The database that will be used if this query is executed now
db
none()
order_by(*fields)
intermediate models
11. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
12. This query finds all entries between a start date of start_date and an end date of end_date.
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
help_text
primary_key
13. 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
F()
none()
pickling
year
14. Lookup type that yields a case-insensitive match.
iexact
order_by(*fields)
get_absolute_url()
OneToOneField
15. If this option is True - the field is allowed to be blank. Default is False.
blank
values(*fields)
Entry.objects.filter(id__gt=4)
clear() method
16. This model method is used for updating a ManyToManyField.
range
add()
annotate(args - *kwargs)
ForeignKey
17. These methods are intended to do "table-wide" things.
update(**kwargs)
filter(**kwargs)
Manager methods
add()
18. 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.
istartswith
reverse()
primary_key
pickling
19. 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
==
when you add new apps to INSTALLED_APPS
select_related()
Meta class
20. 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.
get_absolute_url()
create(**kwargs)
only(*fields)
pickling
21. Lookup type for date/datetime fields that finds a 'day of the week' match.
iregex
many-to-many relationship
Multi-table inheritance
week_day
22. Exception raised by get(**kwargs) if more than one item matches the query.
in
MultipleObjectsReturned
related_name
distinct()
23. a QuerySet can be sliced - using Python's array-slicing syntax.
db
reverse name
MultipleObjectsReturned
slicing
24. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
Meta class
many-to-one relationship
Manager
25. Returns the most recent object in the table - by date - using the field_name provided as the date field.
get(**kwargs)
range
latest(field_name=None)
blank
26. Lookup type that returns results greater than a given value.
aggregate(args - *kwargs)
gt
slicing
save()
27. 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
Entry.objects.filter(id__in=[1 - 3 - 4])
pk
filter chaining
28. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
through argument
default
Field lookups
gte
29. Lookup type that finds a case-sensitive regular expression match.
regex
istartswith
year
add()
30. Lookup type that returns results in a given list.
add()
select_related()
search
in
31. If True - this field is the primary key for the model.
day
gt
filter
primary_key
32. 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
model
all()
iregex
Multi-table inheritance
33. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
in
intermediate models
lt
help_text
34. When to run syncdb
reverse()
when you add new apps to INSTALLED_APPS
endswith
Entry.objects.filter(pub_date__year=2005).delete()
35. Lookup type that finds a case-insensitive regular expression match.
add()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
iregex
using(alias)
36. 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.
related_name
Restrictions on field names
update()
annotate(args - *kwargs)
37. Conjuntion operator for Q objects.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Many-to-many relationship through an intermediate model
class type
&
38. Lookup type that returns results with a case-insensitive start sequence.
ordered
istartswith
Many-to-many relationship through an intermediate model
Manager methods
39. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
dates(field - kind - order='ASC')
Many-to-many relationship through an intermediate model
related_name
40. Manager method used to retrieve every object in a model.
all()
dates(field - kind - order='ASC')
evaluation
search
41. 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.
null
latest(field_name=None)
exact
db
42. 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
lte
values(*fields)
save()
iterator()
43. This model method saves a model instance to the database. This method has no return value.
choices
filter
save()
Model metadata
44. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
default
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
choices tuple
45. Lookup type that tests for inclusion in a case-sensitive fashion.
many-to-many relationship
intermediate models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
contains
46. 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])
Many-to-many relationship to self
model
clear() method
47. A convenience method for looking up an object with the given kwargs - creating one if necessary.
db
exclude(**kwargs)
pickling
get_or_create(**kwargs)
48. Returns the object matching the given lookup parameters
all()
Entry.objects.filter(pub_date__range=(start_date - end_date))
iterator()
get(**kwargs)
49. 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
F()
Manager
update(**kwargs)
isnull
50. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
get(**kwargs)
startswith
==
latest(field_name=None)