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. This model method saves a model instance to the database. This method has no return value.
Field lookups
Custom model methods
save()
help_text
2. Lookup type that finds a case-sensitive regular expression match.
all()
gte
range
regex
3. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
month
select_related()
get_or_create(**kwargs)
4. Exception raised by get(**kwargs) if no items match the query.
add()
DoesNotExist
range
Entry.objects.filter(pub_date__year=2005).delete()
5. 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.
search
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
regex
Entry.objects.filter(pub_date__year=2005).delete()
6. 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.
choices
exact
only(*fields)
pickling
7. This represents a collection of objects from your database. It can have zero - one or many filters.
reverse name
iregex
QuerySet
Restrictions on field names
8. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
when you add new apps to INSTALLED_APPS
update()
isnull
latest(field_name=None)
9. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
day
defer(*fields)
istartswith
10. 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.
null
Multi-table inheritance
many-to-one relationship
slicing
11. Lookup type for date/datetime fields that finds a 'day of the week' match.
default
week_day
delete()
none()
12. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
filter(**kwargs)
only(*fields)
==
id field
13. 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.
only(*fields)
ForeignKey
QuerySet
get(**kwargs)
14. Fields are specified by these
class attributes
get_or_create(**kwargs)
__unicode__()
default
15. Lookup type that yields a case-insensitive match.
reverse()
iexact
week_day
==
16. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
create(**kwargs)
update(**kwargs)
count()
regex
17. 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.
primary_key
lt
Many-to-many relationship to self
clear() method
18. This query finds all entries with an id in the list [1 - 3 - 4]
Many-to-many relationship through an intermediate model
Entry.objects.filter(id__in=[1 - 3 - 4])
iregex
count()
19. Keyword shortcut for looking up an object by primary key.
pk
choices
gt
Meta class
20. The default for this is the name of the child class followed by '_set'.
reverse name
all()
iterator()
update()
21. 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.
default
month
ForeignKey
filter(**kwargs)
22. Manager method used to retrieve every object in a model.
all()
count()
when you add new apps to INSTALLED_APPS
model
23. 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.
using(alias)
distinct()
Q()
get_absolute_url()
24. 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.
through argument
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
__unicode__()
help_text
25. 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.
choices
update(**kwargs)
Q()
search
26. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
iteration
order_by(*fields)
filter(**kwargs)
model
27. 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.
Custom model methods
delete()
get(**kwargs)
class type
28. 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 through an intermediate model
DoesNotExist
pk
many-to-many relationship
29. Conjuntion operator for Q objects.
&
gt
save()
ForeignKey
30. 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.
aggregate(args - *kwargs)
default
isnull
values(*fields)
31. Returns the object matching the given lookup parameters
month
choices tuple
values_list(*fields)
get(**kwargs)
32. Lookup type that returns results greater than or equal to a given value.
gte
exists()
month
update(**kwargs)
33. a QuerySet can be sliced - using Python's array-slicing syntax.
update(**kwargs)
choices
slicing
get_absolute_url()
34. The database that will be used if this query is executed now
MultipleObjectsReturned
db
get_absolute_url()
all()
35. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Meta class
filter chaining
one-to-one relationship
using(alias)
36. 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
relationship spanning
iterator()
count()
iendswith
37. Lookup type that returns results that fall into an inclusive date range.
relationship spanning
__unicode__()
default
range
38. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th
choices tuple
exists()
delete()
delete()
39. 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.
isnull
Entry.objects.filter(pub_date__range=(start_date - end_date))
null
in_bulk(id_list)
40. This query finds all entries between a start date of start_date and an end date of end_date.
count()
Manager methods
reverse()
Entry.objects.filter(pub_date__range=(start_date - end_date))
41. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
MultipleObjectsReturned
values(*fields)
aggregate(args - *kwargs)
null
42. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()
get(**kwargs)
evaluation
range
null
43. These methods are intended to do "table-wide" things.
Manager
filter chaining
lte
Manager methods
44. When to run syncdb
day
only(*fields)
Abstract base class
when you add new apps to INSTALLED_APPS
45. 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
unique
class type
select_related()
Restrictions on field names
46. Lookup type that returns results with a case-sensitive end sequence.
Entry.objects.filter(id__gt=4)
endswith
db
gte
47. Lookup type that returns results in a given list.
in
Abstract base class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exists()
48. 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
evaluation
Many-to-many relationship to self
&
defer(*fields)
49. If True - this field is the primary key for the model.
latest(field_name=None)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
exists()
primary_key
50. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
DoesNotExist
ManyToManyField
Field lookups
__unicode__()