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. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
primary_key
only(*fields)
exists()
filter(**kwargs)
2. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Field lookups
reverse name
get_absolute_url()
3. 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.
Entry.objects.filter(id__gt=4)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
exact
iteration
4. 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
count()
week_day
distinct()
iterator()
5. Lookup type that returns results with a case-insensitive start sequence.
when you add new apps to INSTALLED_APPS
choices
istartswith
Manager methods
6. (1) These cannot be Python reserved words - because that would result in a Python syntax error. (2) These cannot contain more than one underscore in a row - due to the way Django's query lookup syntax works.
iterator()
Multi-table inheritance
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Restrictions on field names
7. Lookup type that finds a case-sensitive regular expression match.
Abstract base class
gte
Custom model methods
regex
8. 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
__unicode__()
Model metadata
save()
9. Lookup type that returns results with a case-sensitive start sequence.
startswith
Abstract base class
Entry.objects.filter(pub_date__year=2005).delete()
DoesNotExist
10. 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.
when you add new apps to INSTALLED_APPS
using(alias)
day
OneToOneField
11. 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
add()
reverse()
update(**kwargs)
latest(field_name=None)
12. Returns the most recent object in the table - by date - using the field_name provided as the date field.
save()
latest(field_name=None)
Q(question__istartswith='What')
DoesNotExist
13. If True - the table does not permit duplicate values for this field.
unique
none()
class type
exists()
14. Negation operator for Q objects.
~
null
iexact
blank
15. Keyword shortcut for looking up an object by primary key.
count()
pk
get(**kwargs)
Custom model methods
16. 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)
related_name
Model metadata
Entry.objects.filter(pub_date__year=2005).delete()
iexact
17. Lookup type that yields a case-insensitive match.
update(**kwargs)
iexact
all()
filter(**kwargs)
18. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
all()
iteration
update(**kwargs)
get(**kwargs)
19. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
ManyToManyField
startswith
&
20. 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
default
primary_key
get_or_create(**kwargs)
through argument
21. a QuerySet can be sliced - using Python's array-slicing syntax.
Restrictions on field names
slicing
Field lookups
regex
22. Lookup type for date/datetime fields that finds an exact day match.
DoesNotExist
relationship spanning
null
day
23. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
__unicode__()
contains
==
24. Used to get a QuerySet for a model. This is called 'objects' by default.
Custom model methods
Restrictions on field names
Manager
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
25. 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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
one-to-one relationship
search
slicing
26. 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.
get_or_create(**kwargs)
select_related()
year
Q()
27. These add custom "row-level" functionality to your objects. These act on a particular model instance.
clear() method
Entry.objects.filter(id__in=[1 - 3 - 4])
Custom model methods
Entry.objects.filter(pub_date__year=2005).delete()
28. Lookup type that returns results with a case-sensitive end sequence.
endswith
when you add new apps to INSTALLED_APPS
in_bulk(id_list)
&
29. 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.
help_text
ManyToManyField
Field lookups
null
30. 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()
get_absolute_url()
filter
Q(question__istartswith='What')
31. If this option is True - the field is allowed to be blank. Default is False.
Field lookups
filter chaining
blank
many-to-many relationship
32. 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
class type
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
gte
default
33. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
unique
pickling
delete()
34. 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()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
when you add new apps to INSTALLED_APPS
class attributes
35. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
create(**kwargs)
lte
through argument
36. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
get_absolute_url()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
one-to-one relationship
order_by(*fields)
37. Lookup type that returns results greater than or equal to a given value.
gte
Field lookups
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
==
38. Disjunction operator for Q objects.
|
filter(**kwargs)
delete()
lt
39. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
all()
filter chaining
get(**kwargs)
40. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
pickling
Manager
month
update(**kwargs)
41. 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
Many-to-many relationship through an intermediate model
defer(*fields)
get(**kwargs)
exact
42. If True - this field is the primary key for the model.
update()
delete()
primary_key
defer(*fields)
43. The database that will be used if this query is executed now
dates(field - kind - order='ASC')
contains
db
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
44. 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.
add()
Abstract base class
==
aggregate(args - *kwargs)
45. This method immediately deletes the object and has no return value.
delete()
clear() method
search
aggregate(args - *kwargs)
46. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Entry.objects.filter(pub_date__year=2005).delete()
all()
Field lookups
==
47. When to run syncdb
unique
when you add new apps to INSTALLED_APPS
range
OneToOneField
48. 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
all()
month
update(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
49. Lookup type that returns results with a case-insensitive end sequence.
Many-to-many relationship to self
many-to-one relationship
Abstract base class
iendswith
50. Defined by django.db.models.ForeignKey. You use it just like any other Field type: by including it as a class attribute of your model.
pk
count()
many-to-one relationship
class attributes