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. 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.
gte
select_related()
filter
aggregate(args - *kwargs)
2. If True - the table does not permit duplicate values for this field.
unique
Entry.objects.filter(pub_date__year=2005).delete()
only(*fields)
iexact
3. 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
select_related()
gt
choices
Abstract base class
4. Lookup type that yields a case-insensitive match.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
iexact
Meta class
delete()
5. 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.
only(*fields)
Restrictions on field names
exclude(**kwargs)
using(alias)
6. This model method saves a model instance to the database. This method has no return value.
iendswith
save()
year
reverse()
7. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
db
DoesNotExist
get(**kwargs)
8. 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
one-to-one relationship
get(**kwargs)
defer(*fields)
Manager
9. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Many-to-many relationship through an intermediate model
Custom model methods
reverse name
dates(field - kind - order='ASC')
10. Conjuntion operator for Q objects.
many-to-many relationship
day
&
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
11. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
delete()
select_related()
Q()
Entry.objects.filter(pub_date__range=(start_date - end_date))
12. 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.
intermediate models
in_bulk(id_list)
regex
help_text
13. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
distinct()
get_absolute_url()
in
model
14. Disjunction operator for Q objects.
related_name
update()
id field
|
15. 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
Restrictions on field names
iterator()
id field
Custom model methods
16. 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
gte
relationship spanning
model
help_text
17. Lookup type that returns results less than or equal to a given value.
regex
lte
annotate(args - *kwargs)
id field
18. This model method is used for updating a ManyToManyField.
lt
add()
istartswith
get(**kwargs)
19. Keyword shortcut for looking up an object by primary key.
isnull
iregex
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
pk
20. 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.
pickling
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Proxy model
update()
21. A convenience method for constructing an object and saving it all in one step.
startswith
iexact
gt
create(**kwargs)
22. These methods are intended to do "table-wide" things.
unique
one-to-one relationship
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Manager methods
23. 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.
choices
Entry.objects.filter(id__gt=4)
search
choices tuple
24. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
|
ordered
intermediate models
Proxy model
25. 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
iteration
when you add new apps to INSTALLED_APPS
get(**kwargs)
all()
26. 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
27. Lookup type that returns results with a case-sensitive end sequence.
endswith
filter
Manager methods
in_bulk(id_list)
28. Used to get a QuerySet for a model. This is called 'objects' by default.
==
update()
Manager
Many-to-many relationship through an intermediate model
29. Lookup type for date/datetime fields that finds a 'day of the week' match.
iterator()
Entry.objects.filter(id__in=[1 - 3 - 4])
get(**kwargs)
week_day
30. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
all()
ordered
F()
only(*fields)
31. To activate your models
Many-to-many relationship to self
OneToOneField
save()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
32. Negation operator for Q objects.
Abstract base class
~
gt
clear() method
33. 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)
Custom model methods
week_day
Entry.objects.filter(pub_date__range=(start_date - end_date))
34. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
ForeignKey
Many-to-many relationship through an intermediate model
month
through argument
35. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
create(**kwargs)
Multi-table inheritance
get_absolute_url()
iterator()
36. A convenience method for looking up an object with the given kwargs - creating one if necessary.
DoesNotExist
get_or_create(**kwargs)
ordered
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
37. 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.
iexact
get_absolute_url()
many-to-one relationship
pickling
38. 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.
Many-to-many relationship to self
none()
month
exists()
39. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
select_related()
Manager
Q(question__istartswith='What')
MultipleObjectsReturned
40. 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
DoesNotExist
update(**kwargs)
filter(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
41. 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)
contains
when you add new apps to INSTALLED_APPS
Entry.objects.filter(id__gt=4)
42. Lookup type that tests for inclusion in a case-sensitive fashion.
Many-to-many relationship through an intermediate model
ManyToManyField
contains
annotate(args - *kwargs)
43. The default for this is the name of the child class followed by '_set'.
blank
reverse()
none()
reverse name
44. Lookup type that returns results with a case-insensitive end sequence.
week_day
reverse name
iendswith
Entry.objects.filter(pub_date__year=2005).delete()
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 one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.
&
startswith
OneToOneField
exclude(**kwargs)
47. Lookup type that returns results that fall into an inclusive date range.
pk
reverse()
range
id field
48. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
blank
aggregate(args - *kwargs)
many-to-one relationship
49. 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.
reverse()
count()
get_absolute_url()
many-to-many relationship
50. This represents a collection of objects from your database. It can have zero - one or many filters.
iregex
QuerySet
Manager
Restrictions on field names