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. 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.
delete()
get_absolute_url()
pickling
iregex
2. Exception raised by get(**kwargs) if more than one item matches the query.
Q()
values_list(*fields)
MultipleObjectsReturned
default
3. Lookup type that returns results greater than a given value.
Entry.objects.filter(id__gt=4)
gt
get_or_create(**kwargs)
istartswith
4. 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.
using(alias)
default
values_list(*fields)
order_by(*fields)
5. 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.
year
startswith
values_list(*fields)
reverse()
6. Lookup type that finds a case-sensitive regular expression match.
get_or_create(**kwargs)
MultipleObjectsReturned
iteration
regex
7. Lookup type that yields a case-insensitive match.
values(*fields)
when you add new apps to INSTALLED_APPS
iexact
none()
8. 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.
OneToOneField
exact
isnull
get(**kwargs)
9. Disjunction operator for Q objects.
|
model
through argument
Manager
10. 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.
update()
evaluation
choices tuple
primary_key
11. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
&
__unicode__()
range
12. This is a criterion that narrow down a QuerySet based on given parameters.
filter
get_or_create(**kwargs)
&
class type
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.
iregex
Many-to-many relationship to self
Entry.objects.filter(pub_date__range=(start_date - end_date))
aggregate(args - *kwargs)
14. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
only(*fields)
Many-to-many relationship to self
gte
15. Fields are specified by these
Entry.objects.filter(pub_date__year=2005).delete()
values_list(*fields)
class attributes
gt
16. 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.
Entry.objects.filter(id__gt=4)
Abstract base class
clear() method
in_bulk(id_list)
17. 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
18. 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.
Manager methods
Entry.objects.filter(id__gt=4)
search
iendswith
19. 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()
values(*fields)
filter(**kwargs)
evaluation
QuerySet
20. The database that will be used if this query is executed now
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
&
db
gte
21. Lookup type that returns results with a case-sensitive start sequence.
__unicode__()
startswith
evaluation
defer(*fields)
22. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
values_list(*fields)
Field lookups
relationship spanning
class type
23. This field is added automatically - but this behavior can be overridden
id field
isnull
all()
db
24. 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
default
evaluation
select_related()
class type
25. 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
choices
Field lookups
one-to-one relationship
annotate(args - *kwargs)
26. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Entry.objects.filter(id__in=[1 - 3 - 4])
delete()
pk
related_name
27. Conjuntion operator for Q objects.
&
add()
Q()
Entry.objects.filter(pub_date__year=2005).delete()
28. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Manager methods
year
lt
get_or_create(**kwargs)
29. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
iendswith
F()
evaluation
Restrictions on field names
30. 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
many-to-one relationship
only(*fields)
defer(*fields)
year
31. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
reverse name
in
help_text
32. This query deletes all Entry objects with a pub_date year of 2005.
latest(field_name=None)
MultipleObjectsReturned
pk
Entry.objects.filter(pub_date__year=2005).delete()
33. Lookup type for date/datetime fields that finds an exact day match.
Many-to-many relationship to self
add()
day
primary_key
34. Lookup type that returns results less than a given value.
choices
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
lt
update(**kwargs)
35. 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
reverse name
week_day
get(**kwargs)
iterator()
36. 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
37. If True - this field is the primary key for the model.
primary_key
gt
using(alias)
Entry.objects.filter(pub_date__year=2005).delete()
38. 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
39. Lookup type that returns results with a case-insensitive start sequence.
istartswith
class attributes
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
aggregate(args - *kwargs)
40. This model method is used for updating a ManyToManyField.
get_absolute_url()
all()
add()
Entry.objects.filter(pub_date__range=(start_date - end_date))
41. Lookup type that returns results less than or equal to a given value.
lte
values_list(*fields)
save()
through argument
42. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
pk
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
get_or_create(**kwargs)
43. Lookup type that returns results greater than or equal to a given value.
Custom model methods
related_name
gte
year
44. 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.
order_by(*fields)
get_or_create(**kwargs)
aggregate(args - *kwargs)
exists()
45. 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
46. 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.
reverse()
ForeignKey
week_day
choices
47. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
Proxy model
ordered
iteration
|
48. In some complex data-modeling situations - your models might contain a lot of fields - some of which could contain a lot of data (for example - text fields) - or require expensive processing to convert them to Python objects. If you are using the res
defer(*fields)
get_absolute_url()
__unicode__()
through argument
49. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
endswith
one-to-one relationship
Field lookups
Manager methods
50. 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.
F()
ForeignKey
evaluation
Many-to-many relationship to self