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 True - this field is the primary key for the model.
primary_key
distinct()
null
Restrictions on field names
2. Lookup type that returns results that fall into an inclusive date range.
get(**kwargs)
distinct()
ordered
range
3. 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
relationship spanning
update()
id field
get_or_create(**kwargs)
4. Lookup type for date/datetime fields that finds a 'day of the week' match.
many-to-one relationship
week_day
Custom model methods
values_list(*fields)
5. 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
6. 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.
ForeignKey
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
gt
lte
7. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
choices
month
Restrictions on field names
8. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
using(alias)
aggregate(args - *kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
9. 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()
many-to-one relationship
Multi-table inheritance
&
10. 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
none()
exists()
ForeignKey
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
11. Lookup type that yields a case-insensitive match.
filter(**kwargs)
iexact
Entry.objects.filter(pub_date__year=2005).delete()
QuerySet
12. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
primary_key
model
iendswith
13. 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
14. This query finds all entries with an id greater than 4.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
values_list(*fields)
Entry.objects.filter(id__gt=4)
all()
15. 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
exists()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
update(**kwargs)
defer(*fields)
16. 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
iterator()
&
null
ManyToManyField
17. These methods are intended to do "table-wide" things.
ForeignKey
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Manager methods
week_day
18. This field is added automatically - but this behavior can be overridden
Restrictions on field names
delete()
id field
contains
19. 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
20. 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 tuple
in_bulk(id_list)
many-to-one relationship
QuerySet
21. A convenience method for constructing an object and saving it all in one step.
MultipleObjectsReturned
Abstract base class
create(**kwargs)
==
22. This model method is used for updating a ManyToManyField.
Manager
gt
add()
all()
23. 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.
get_absolute_url()
F()
in_bulk(id_list)
help_text
24. Lookup type that finds a case-insensitive regular expression match.
unique
order_by(*fields)
all()
iregex
25. Negation operator for Q objects.
~
distinct()
month
|
26. 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.
Multi-table inheritance
default
null
update()
27. 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.
none()
choices
choices tuple
year
28. Lookup type that returns results greater than or equal to a given value.
annotate(args - *kwargs)
delete()
gte
only(*fields)
29. Lookup type for date/datetime fields that finds an exact day match.
==
day
filter(**kwargs)
ordered
30. When to run syncdb
Manager methods
pk
using(alias)
when you add new apps to INSTALLED_APPS
31. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
range
only(*fields)
one-to-one relationship
filter(**kwargs)
32. 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.
contains
in_bulk(id_list)
gte
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
33. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
all()
Abstract base class
update(**kwargs)
34. If True - the table does not permit duplicate values for this field.
OneToOneField
values(*fields)
unique
iexact
35. If this option is True - the field is allowed to be blank. Default is False.
values(*fields)
filter(**kwargs)
get(**kwargs)
blank
36. Keyword shortcut for looking up an object by primary key.
Field lookups
pk
search
iterator()
37. 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.
select_related()
reverse()
Q()
week_day
38. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
ForeignKey
week_day
intermediate models
39. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
pickling
default
__unicode__()
Many-to-many relationship to self
40. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
get_or_create(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
model
41. This tells Django how to calculate the URL for an object. Django uses this in its admin interface - and any time it needs to figure out a URL for an object.
get_absolute_url()
through argument
values_list(*fields)
startswith
42. 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.
ForeignKey
related_name
add()
delete()
43. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
iexact
update()
iregex
44. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
contains
range
Manager methods
many-to-many relationship
45. 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)
==
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
clear() method
46. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
OneToOneField
evaluation
values(*fields)
order_by(*fields)
47. The default for this is the name of the child class followed by '_set'.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
month
OneToOneField
reverse name
48. 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.
pickling
many-to-one relationship
using(alias)
DoesNotExist
49. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
dates(field - kind - order='ASC')
ForeignKey
save()
50. 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.
exact
values_list(*fields)
class attributes
aggregate(args - *kwargs)