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. Disjunction operator for Q objects.
|
in
istartswith
Entry.objects.filter(pub_date__range=(start_date - end_date))
2. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
dates(field - kind - order='ASC')
&
Field lookups
get(**kwargs)
3. These methods are intended to do "table-wide" things.
count()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Manager methods
pk
4. This field is added automatically - but this behavior can be overridden
unique
id field
class attributes
model
5. These add custom "row-level" functionality to your objects. These act on a particular model instance.
isnull
evaluation
Custom model methods
help_text
6. 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
class type
choices
reverse()
update()
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 metadata
get(**kwargs)
ManyToManyField
model
8. Returns the most recent object in the table - by date - using the field_name provided as the date field.
none()
delete()
latest(field_name=None)
dates(field - kind - order='ASC')
9. 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
iterator()
only(*fields)
filter chaining
contains
10. This represents a collection of objects from your database. It can have zero - one or many filters.
many-to-one relationship
QuerySet
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
class type
11. Manager method used to retrieve every object in a model.
iexact
aggregate(args - *kwargs)
update()
all()
12. 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
null
delete()
gt
update(**kwargs)
13. 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.
filter(**kwargs)
select_related()
many-to-one relationship
aggregate(args - *kwargs)
14. Returns the object matching the given lookup parameters
aggregate(args - *kwargs)
contains
filter(**kwargs)
get(**kwargs)
15. This query deletes all Entry objects with a pub_date year of 2005.
many-to-many relationship
Entry.objects.filter(pub_date__year=2005).delete()
get_or_create(**kwargs)
using(alias)
16. Lookup type that finds a case-sensitive regular expression match.
db
Entry.objects.filter(pub_date__year=2005).delete()
default
regex
17. Lookup type that returns results with a case-insensitive start sequence.
Manager
all()
Entry.objects.filter(id__gt=4)
istartswith
18. 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.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
ordered
slicing
values_list(*fields)
19. 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.
Field lookups
month
using(alias)
many-to-one relationship
20. Lookup type for date/datetime fields that finds an exact day match.
QuerySet
clear() method
day
filter(**kwargs)
21. 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.
Restrictions on field names
many-to-one relationship
iteration
Meta class
22. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
exact
iendswith
values(*fields)
23. 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
24. Lookup type for date/datetime fields that finds a 'day of the week' match.
relationship spanning
filter
Q()
week_day
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.
choices
annotate(args - *kwargs)
ManyToManyField
values_list(*fields)
26. 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)
Multi-table inheritance
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
intermediate models
27. Lookup type that returns results that fall into an inclusive date range.
range
|
many-to-one relationship
ForeignKey
28. Lookup type that returns results greater than a given value.
range
help_text
id field
gt
29. Lookup type that returns results with a case-sensitive end sequence.
endswith
Manager methods
&
__unicode__()
30. a QuerySet can be sliced - using Python's array-slicing syntax.
Field lookups
none()
slicing
pickling
31. 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
Field lookups
contains
exists()
search
32. 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.
iregex
year
through argument
33. Lookup type that returns results greater than or equal to a given value.
endswith
Meta class
gte
day
34. Defines a many-to-one relationship. ou use it just like any other Field type: by including it as a class attribute of your model.
Model metadata
related_name
ForeignKey
week_day
35. This query finds all entries between a start date of start_date and an end date of end_date.
default
Entry.objects.filter(pub_date__range=(start_date - end_date))
values(*fields)
MultipleObjectsReturned
36. When to run syncdb
blank
latest(field_name=None)
when you add new apps to INSTALLED_APPS
get_absolute_url()
37. 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.
Manager methods
update()
&
iendswith
38. 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
39. 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
relationship spanning
ordered
Q()
40. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
using(alias)
filter chaining
41. Exception raised by get(**kwargs) if more than one item matches the query.
latest(field_name=None)
MultipleObjectsReturned
Entry.objects.filter(id__in=[1 - 3 - 4])
iteration
42. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
OneToOneField
in
Field lookups
filter(**kwargs)
43. This gives your model metadata.
ManyToManyField
Meta class
iterator()
Q(question__istartswith='What')
44. 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.
Restrictions on field names
Entry.objects.filter(pub_date__range=(start_date - end_date))
ManyToManyField
search
45. Lookup type that tests for inclusion in a case-sensitive fashion.
Many-to-many relationship through an intermediate model
update(**kwargs)
lte
contains
46. 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.
ForeignKey
Many-to-many relationship to self
select_related()
in
47. Negation operator for Q objects.
iendswith
~
search
order_by(*fields)
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
filter
MultipleObjectsReturned
Q()
49. If True - this field is the primary key for the model.
isnull
primary_key
OneToOneField
one-to-one relationship
50. 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.
iregex
help_text
exact
in_bulk(id_list)