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. 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
annotate(args - *kwargs)
gte
&
many-to-one relationship
2. 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.
Field lookups
Restrictions on field names
Multi-table inheritance
iregex
3. Lookup type that returns results in a given list.
default
in
week_day
Meta class
4. 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.
delete()
Entry.objects.filter(pub_date__range=(start_date - end_date))
none()
filter chaining
5. 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.
lte
OneToOneField
filter chaining
create(**kwargs)
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.
isnull
using(alias)
delete()
pk
7. Lookup type for date/datetime fields that finds an exact day match.
none()
day
exact
db
8. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
distinct()
count()
in
Entry.objects.filter(pub_date__range=(start_date - end_date))
9. 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
10. Returns the object matching the given lookup parameters
istartswith
Abstract base class
get(**kwargs)
one-to-one relationship
11. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
through argument
endswith
==
ManyToManyField
12. If True - this field is the primary key for the model.
F()
Field lookups
ordered
primary_key
13. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
year
~
month
Entry.objects.filter(pub_date__range=(start_date - end_date))
14. If this option is True - Django will store empty values as NULL in the database. Default is False.
when you add new apps to INSTALLED_APPS
__unicode__()
null
OneToOneField
15. This model method is used for updating a ManyToManyField.
Q()
using(alias)
add()
related_name
16. 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
17. A convenience method for looking up an object with the given kwargs - creating one if necessary.
regex
get_or_create(**kwargs)
Model metadata
delete()
18. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
choices
all()
save()
19. Fields are specified by these
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Entry.objects.filter(pub_date__year=2005).delete()
QuerySet
class attributes
20. This gives your model metadata.
Meta class
choices tuple
annotate(args - *kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
21. 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.
get(**kwargs)
filter chaining
aggregate(args - *kwargs)
in
22. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
many-to-many relationship
model
lt
all()
23. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
class attributes
pickling
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
24. 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
Proxy model
MultipleObjectsReturned
update(**kwargs)
primary_key
25. A Python "magic method" that returns a unicode "representation" of any object.
slicing
pk
__unicode__()
filter(**kwargs)
26. If True - the table does not permit duplicate values for this field.
exists()
unique
values(*fields)
blank
27. 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
intermediate models
Abstract base class
null
db
28. 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
29. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
choices
only(*fields)
values_list(*fields)
model
30. Can be used to remove all many-to-many relationships for an instance
clear() method
null
iexact
month
31. 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
exclude(**kwargs)
iterator()
only(*fields)
through argument
32. A convenience method for constructing an object and saving it all in one step.
QuerySet
create(**kwargs)
in_bulk(id_list)
class type
33. 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
unique
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
reverse()
defer(*fields)
34. 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
35. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
iendswith
OneToOneField
pickling
36. 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
regex
Abstract base class
ordered
order_by(*fields)
37. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
reverse name
get_or_create(**kwargs)
iteration
ordered
38. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
blank
values(*fields)
none()
Restrictions on field names
39. Negation operator for Q objects.
week_day
default
Q(question__istartswith='What')
~
40. 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.
using(alias)
QuerySet
ManyToManyField
all()
41. 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
select_related()
only(*fields)
create(**kwargs)
db
42. 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()
|
startswith
week_day
43. If this option is True - the field is allowed to be blank. Default is False.
Restrictions on field names
Proxy model
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
blank
44. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
exclude(**kwargs)
ManyToManyField
clear() method
45. 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)
QuerySet
lt
ForeignKey
Model metadata
46. 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.
distinct()
delete()
annotate(args - *kwargs)
MultipleObjectsReturned
47. When to run syncdb
save()
lte
id field
when you add new apps to INSTALLED_APPS
48. Returns a new QuerySet containing objects that match the given lookup parameters.
ordered
filter(**kwargs)
choices
get_or_create(**kwargs)
49. 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
50. 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.
Restrictions on field names
get_or_create(**kwargs)
exact
order_by(*fields)