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. Lookup type that returns results with a case-insensitive start sequence.
Entry.objects.filter(pub_date__year=2005).delete()
DoesNotExist
one-to-one relationship
istartswith
2. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
unique
OneToOneField
ForeignKey
3. If True - the table does not permit duplicate values for this field.
reverse()
week_day
OneToOneField
unique
4. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
iexact
aggregate(args - *kwargs)
month
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
5. If True - this field is the primary key for the model.
week_day
|
iterator()
primary_key
6. Returns the object matching the given lookup parameters
get(**kwargs)
all()
Proxy model
week_day
7. 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
__unicode__()
intermediate models
lt
Entry.objects.filter(pub_date__range=(start_date - end_date))
8. Lookup type that yields a case-insensitive match.
week_day
MultipleObjectsReturned
update()
iexact
9. 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.
related_name
filter(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
help_text
10. Lookup type for date/datetime fields that finds a 'day of the week' match.
exact
week_day
latest(field_name=None)
null
11. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
id field
one-to-one relationship
endswith
choices
12. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
intermediate models
iteration
ordered
reverse()
13. 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.
all()
get(**kwargs)
Model metadata
__unicode__()
14. 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
using(alias)
Restrictions on field names
Entry.objects.filter(pub_date__range=(start_date - end_date))
select_related()
15. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Q(question__istartswith='What')
Field lookups
default
get_or_create(**kwargs)
16. 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.
in_bulk(id_list)
QuerySet
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.
17. This method immediately deletes the object and has no return value.
Abstract base class
delete()
select_related()
values(*fields)
18. Lookup type that finds a case-sensitive regular expression match.
~
__unicode__()
range
regex
19. 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
F()
class type
clear() method
ManyToManyField
20. 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.
pickling
iendswith
Multi-table inheritance
==
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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
through argument
when you add new apps to INSTALLED_APPS
delete()
22. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
null
dates(field - kind - order='ASC')
day
ordered
23. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
Q()
gt
QuerySet
24. Lookup type that returns results greater than or equal to a given value.
values_list(*fields)
evaluation
annotate(args - *kwargs)
gte
25. Lookup type that returns results less than a given value.
model
iendswith
reverse()
lt
26. 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.
update(**kwargs)
get_or_create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Field lookups
27. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
many-to-one relationship
endswith
reverse name
28. 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
29. 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)
filter
annotate(args - *kwargs)
Model metadata
gte
30. These add custom "row-level" functionality to your objects. These act on a particular model instance.
latest(field_name=None)
Custom model methods
pk
create(**kwargs)
31. 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
32. This query finds all entries with an id greater than 4.
gt
add()
exclude(**kwargs)
Entry.objects.filter(id__gt=4)
33. Lookup type that returns results with a case-insensitive end sequence.
iterator()
filter chaining
iendswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
34. This query deletes all Entry objects with a pub_date year of 2005.
pk
Entry.objects.filter(pub_date__year=2005).delete()
Custom model methods
Abstract base class
35. A convenience method for looking up an object with the given kwargs - creating one if necessary.
class attributes
get_or_create(**kwargs)
intermediate models
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
36. Can be used to remove all many-to-many relationships for an instance
lte
clear() method
isnull
iexact
37. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
through argument
slicing
related_name
week_day
38. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
create(**kwargs)
add()
select_related()
many-to-many relationship
39. This gives your model metadata.
evaluation
Meta class
class attributes
latest(field_name=None)
40. 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.
delete()
F()
regex
choices
41. 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.
week_day
startswith
MultipleObjectsReturned
order_by(*fields)
42. Disjunction operator for Q objects.
year
|
through argument
latest(field_name=None)
43. This model method is used for updating a ManyToManyField.
add()
values(*fields)
annotate(args - *kwargs)
Restrictions on field names
44. 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.
ManyToManyField
exact
==
Abstract base class
45. Lookup type that returns results in a given list.
lt
in
Restrictions on field names
reverse name
46. 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.
class attributes
Entry.objects.filter(id__in=[1 - 3 - 4])
range
Q()
47. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
help_text
==
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
filter(**kwargs)
48. 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.
save()
choices tuple
get_or_create(**kwargs)
select_related()
49. 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.
many-to-many relationship
pickling
QuerySet
intermediate models
50. Manager method used to retrieve every object in a model.
|
all()
choices
count()