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. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
annotate(args - *kwargs)
startswith
order_by(*fields)
2. By default - results returned by a QuerySet are ordered by the ordering tuple given by the ordering option in the model's Meta. You can override this on a per-QuerySet basis by using the this method.
one-to-one relationship
order_by(*fields)
iendswith
many-to-one relationship
3. a QuerySet can be sliced - using Python's array-slicing syntax.
delete()
Entry.objects.filter(id__gt=4)
slicing
add()
4. 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
5. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
none()
one-to-one relationship
Many-to-many relationship through an intermediate model
Field lookups
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.
using(alias)
update(**kwargs)
Model metadata
filter(**kwargs)
7. If True - this field is the primary key for the model.
primary_key
&
endswith
ordered
8. Fields are specified by these
iendswith
latest(field_name=None)
many-to-many relationship
class attributes
9. 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
iteration
ForeignKey
exists()
using(alias)
10. Negation operator for Q objects.
evaluation
~
contains
id field
11. This model method is used for updating a ManyToManyField.
add()
Manager methods
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Q(question__istartswith='What')
12. 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
ordered
slicing
exclude(**kwargs)
class type
13. This query finds all entries between a start date of start_date and an end date of end_date.
filter chaining
day
Entry.objects.filter(pub_date__range=(start_date - end_date))
istartswith
14. 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.
lt
all()
==
ForeignKey
15. 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.
Custom model methods
Manager
~
reverse()
16. Lookup type that tests for inclusion in a case-sensitive fashion.
QuerySet
evaluation
filter chaining
contains
17. This model method saves a model instance to the database. This method has no return value.
gte
save()
Many-to-many relationship through an intermediate model
choices tuple
18. 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.
gt
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Meta class
search
19. 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.
month
related_name
gt
pickling
20. 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.
Entry.objects.filter(id__gt=4)
~
many-to-many relationship
Many-to-many relationship to self
21. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Abstract base class
QuerySet
get_or_create(**kwargs)
gt
22. If True - the table does not permit duplicate values for this field.
reverse()
unique
reverse name
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
23. Lookup type that returns results with a case-insensitive end sequence.
iendswith
dates(field - kind - order='ASC')
iterator()
pk
24. 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
slicing
Restrictions on field names
model
25. The default for this is the name of the child class followed by '_set'.
reverse name
class attributes
class type
startswith
26. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
contains
count()
|
db
27. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
intermediate models
ordered
QuerySet
startswith
28. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
aggregate(args - *kwargs)
delete()
db
intermediate models
29. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
exclude(**kwargs)
==
gt
30. To activate your models
|
Q()
Manager
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
31. 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
32. Lookup type that returns results that fall into an inclusive date range.
Manager methods
delete()
range
using(alias)
33. 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
regex
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in
34. If this option is True - Django will store empty values as NULL in the database. Default is False.
Multi-table inheritance
null
intermediate models
filter
35. 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.
pickling
isnull
reverse name
filter chaining
36. This field is added automatically - but this behavior can be overridden
|
db
filter(**kwargs)
id field
37. Lookup type that returns results with a case-insensitive start sequence.
istartswith
count()
lt
reverse name
38. When to run syncdb
week_day
when you add new apps to INSTALLED_APPS
pk
range
39. 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.
update(**kwargs)
Many-to-many relationship to self
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
search
40. Keyword shortcut for looking up an object by primary key.
pk
isnull
distinct()
__unicode__()
41. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iexact
save()
many-to-many relationship
Many-to-many relationship through an intermediate model
42. Returns the object matching the given lookup parameters
isnull
|
null
get(**kwargs)
43. If this option is True - the field is allowed to be blank. Default is False.
Entry.objects.filter(id__gt=4)
values_list(*fields)
none()
blank
44. 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
QuerySet
Q(question__istartswith='What')
pk
45. 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()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Restrictions on field names
endswith
evaluation
46. Lookup type that returns results less than or equal to a given value.
using(alias)
lte
range
Restrictions on field names
47. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
latest(field_name=None)
Manager methods
related_name
48. Lookup type that finds a case-insensitive regular expression match.
iregex
get_absolute_url()
&
help_text
49. 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
dates(field - kind - order='ASC')
Abstract base class
when you add new apps to INSTALLED_APPS
one-to-one relationship
50. This is a criterion that narrow down a QuerySet based on given parameters.
filter
gt
distinct()
contains