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. 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
values(*fields)
intermediate models
in
iterator()
2. 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
3. If True - the table does not permit duplicate values for this field.
reverse name
unique
clear() method
__unicode__()
4. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
values(*fields)
choices
year
update(**kwargs)
5. Returns the most recent object in the table - by date - using the field_name provided as the date field.
model
latest(field_name=None)
default
filter(**kwargs)
6. 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
|
lt
filter(**kwargs)
7. A Python "magic method" that returns a unicode "representation" of any object.
all()
Q(question__istartswith='What')
__unicode__()
reverse name
8. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
values_list(*fields)
gt
9. Fields are specified by these
class attributes
null
annotate(args - *kwargs)
pickling
10. 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
choices
class type
OneToOneField
evaluation
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.
unique
exclude(**kwargs)
many-to-one relationship
gte
12. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
class attributes
&
through argument
13. 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.
Meta class
create(**kwargs)
week_day
Many-to-many relationship through an intermediate model
14. 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()
Multi-table inheritance
==
pickling
evaluation
15. Negation operator for Q objects.
~
create(**kwargs)
help_text
many-to-many relationship
16. Lookup type for date/datetime fields that finds an exact day match.
&
all()
create(**kwargs)
day
17. 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
intermediate models
slicing
exists()
~
18. Returns the object matching the given lookup parameters
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
choices tuple
QuerySet
get(**kwargs)
19. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
latest(field_name=None)
clear() method
relationship spanning
20. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
|
filter(**kwargs)
QuerySet
using(alias)
21. Manager method used to retrieve every object in a model.
id field
get_or_create(**kwargs)
all()
filter(**kwargs)
22. If this option is True - Django will store empty values as NULL in the database. Default is False.
model
distinct()
null
Custom model methods
23. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
in
get_absolute_url()
pickling
24. 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
evaluation
update(**kwargs)
==
Q()
25. 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.
values_list(*fields)
get(**kwargs)
year
exclude(**kwargs)
26. Lookup type that finds a case-sensitive regular expression match.
clear() method
regex
default
Manager
27. 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.
add()
help_text
update(**kwargs)
pk
28. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
distinct()
Entry.objects.filter(pub_date__range=(start_date - end_date))
gte
29. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
save()
lt
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
30. 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
31. Specifies the model that will be used to govern the many-to-many relationship. You can then put extra fields on the intermediate model. The intermediate model is associated with the ManyToManyField using this to point to the model that will act as an
model
through argument
iexact
Manager methods
32. 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.
get(**kwargs)
aggregate(args - *kwargs)
distinct()
add()
33. Lookup type that returns results with a case-insensitive end sequence.
get_or_create(**kwargs)
using(alias)
order_by(*fields)
iendswith
34. Lookup type for date/datetime fields that finds a 'day of the week' match.
Entry.objects.filter(pub_date__year=2005).delete()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
week_day
add()
35. Lookup type that tests for inclusion in a case-sensitive fashion.
distinct()
contains
values_list(*fields)
Restrictions on field names
36. 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
reverse()
primary_key
none()
Restrictions on field names
37. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
Manager
values_list(*fields)
gt
38. Lookup type that returns results with a case-sensitive end sequence.
help_text
endswith
Entry.objects.filter(id__gt=4)
ordered
39. This query finds all entries with an id greater than 4.
class type
contains
gte
Entry.objects.filter(id__gt=4)
40. 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
41. Lookup type that returns results that fall into an inclusive date range.
filter(**kwargs)
lte
model
range
42. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
one-to-one relationship
filter(**kwargs)
Field lookups
|
43. Conjuntion operator for Q objects.
&
only(*fields)
endswith
Field lookups
44. Lookup type that returns results greater than or equal to a given value.
lte
create(**kwargs)
distinct()
gte
45. 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
dates(field - kind - order='ASC')
Many-to-many relationship through an intermediate model
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
46. 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
47. 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
48. If True - this field is the primary key for the model.
Entry.objects.filter(id__gt=4)
primary_key
select_related()
create(**kwargs)
49. a QuerySet can be sliced - using Python's array-slicing syntax.
search
slicing
null
one-to-one relationship
50. These methods are intended to do "table-wide" things.
contains
Manager methods
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
delete()