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 represents a collection of objects from your database. It can have zero - one or many filters.
delete()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
QuerySet
clear() method
2. Returns the object matching the given lookup parameters
reverse name
when you add new apps to INSTALLED_APPS
get(**kwargs)
dates(field - kind - order='ASC')
3. 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
4. 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
Q()
primary_key
DoesNotExist
class type
5. Lookup type that finds a case-sensitive regular expression match.
Multi-table inheritance
get_or_create(**kwargs)
regex
Meta class
6. The database that will be used if this query is executed now
filter
db
==
clear() method
7. 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.
help_text
order_by(*fields)
when you add new apps to INSTALLED_APPS
get_absolute_url()
8. Lookup type that returns results less than a given value.
lt
QuerySet
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
help_text
9. 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.
clear() method
using(alias)
dates(field - kind - order='ASC')
exact
10. 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.
delete()
reverse()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
related_name
11. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
iteration
aggregate(args - *kwargs)
reverse()
12. This model method is used for updating a ManyToManyField.
regex
add()
slicing
exclude(**kwargs)
13. Keyword shortcut for looking up an object by primary key.
clear() method
pk
order_by(*fields)
null
14. 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.
year
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
choices tuple
contains
15. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
MultipleObjectsReturned
unique
Q()
isnull
16. 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()
model
choices
istartswith
evaluation
17. Lookup type that finds a case-insensitive regular expression match.
F()
gt
blank
iregex
18. Negation operator for Q objects.
exists()
~
ordered
year
19. 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
filter(**kwargs)
update(**kwargs)
iterator()
through argument
20. Lookup type for date/datetime fields that finds an exact day match.
iexact
search
slicing
day
21. 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
through argument
get(**kwargs)
iterator()
iendswith
22. 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
all()
update(**kwargs)
Custom model methods
Model metadata
23. If this option is True - the field is allowed to be blank. Default is False.
exact
blank
class type
get(**kwargs)
24. 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()
search
iregex
Manager
25. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
pk
through argument
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
26. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
range
day
Multi-table inheritance
27. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
endswith
count()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
28. Lookup type that returns results greater than a given value.
in_bulk(id_list)
add()
dates(field - kind - order='ASC')
gt
29. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
exclude(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
defer(*fields)
get(**kwargs)
30. 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.
clear() method
dates(field - kind - order='ASC')
pickling
many-to-one relationship
31. Lookup type that tests for inclusion in a case-sensitive fashion.
==
contains
Many-to-many relationship to self
Many-to-many relationship through an intermediate model
32. Lookup type that returns results with a case-insensitive end sequence.
iendswith
dates(field - kind - order='ASC')
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
&
33. When to run syncdb
&
filter(**kwargs)
when you add new apps to INSTALLED_APPS
null
34. If True - this field is the primary key for the model.
startswith
primary_key
filter
DoesNotExist
35. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
QuerySet
regex
unique
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.
values(*fields)
model
order_by(*fields)
one-to-one relationship
37. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
delete()
startswith
ForeignKey
38. 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.
many-to-many relationship
ForeignKey
regex
Q(question__istartswith='What')
39. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
primary_key
QuerySet
blank
in_bulk(id_list)
40. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
reverse name
none()
select_related()
41. 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.
choices
aggregate(args - *kwargs)
exists()
update(**kwargs)
42. Lookup type for date/datetime fields that finds a 'day of the week' match.
values(*fields)
week_day
iterator()
exclude(**kwargs)
43. 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.
OneToOneField
values_list(*fields)
class attributes
ManyToManyField
44. Disjunction operator for Q objects.
all()
many-to-many relationship
annotate(args - *kwargs)
|
45. This field is added automatically - but this behavior can be overridden
id field
Entry.objects.filter(pub_date__year=2005).delete()
Model metadata
iexact
46. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
DoesNotExist
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
one-to-one relationship
clear() method
47. a QuerySet can be sliced - using Python's array-slicing syntax.
id field
slicing
choices
get(**kwargs)
48. 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
49. 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
reverse()
annotate(args - *kwargs)
&
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
50. 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.
MultipleObjectsReturned
none()
~
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)