SUBJECTS
|
BROWSE
|
CAREER CENTER
|
POPULAR
|
JOIN
|
LOGIN
Business Skills
|
Soft Skills
|
Basic Literacy
|
Certifications
About
|
Help
|
Privacy
|
Terms
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 - the table does not permit duplicate values for this field.
values_list(*fields)
latest(field_name=None)
Q(question__istartswith='What')
unique
2. To activate your models
Q()
iendswith
range
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
3. Lookup type that returns results greater than a given value.
gt
Model metadata
many-to-one relationship
__unicode__()
4. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
isnull
OneToOneField
Q()
5. 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
|
Multi-table inheritance
primary_key
only(*fields)
6. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
only(*fields)
iexact
year
get_or_create(**kwargs)
7. This model type is useful if you only want to modify the Python-level behavior of a model - without changing the models fields in any way. This creates a stand-in for the original model. You can create - delete and update instances of this new model
reverse()
dates(field - kind - order='ASC')
Proxy model
choices
8. This represents a collection of objects from your database. It can have zero - one or many filters.
aggregate(args - *kwargs)
QuerySet
class type
get(**kwargs)
9. Lookup type that returns results with a case-insensitive start sequence.
istartswith
exact
DoesNotExist
get(**kwargs)
10. 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.
Manager
when you add new apps to INSTALLED_APPS
blank
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
11. 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.
filter
order_by(*fields)
get_absolute_url()
model
12. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
&
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
values(*fields)
lt
13. Lookup type that returns results less than a given value.
exact
month
week_day
lt
14. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
15. If this option is True - the field is allowed to be blank. Default is False.
isnull
relationship spanning
blank
Model metadata
16. This is a criterion that narrow down a QuerySet based on given parameters.
filter
one-to-one relationship
year
blank
17. 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.
startswith
==
in_bulk(id_list)
null
18. 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)
Manager methods
Many-to-many relationship to self
~
19. 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
delete()
filter chaining
order_by(*fields)
20. 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.
range
order_by(*fields)
iendswith
values_list(*fields)
21. Lookup type that yields a case-insensitive match.
iexact
__unicode__()
Multi-table inheritance
get_absolute_url()
22. 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.
create(**kwargs)
only(*fields)
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.
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.
order_by(*fields)
blank
class type
using(alias)
24. (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.
Abstract base class
exists()
null
Restrictions on field names
25. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
in_bulk(id_list)
iteration
iterator()
contains
26. 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)
week_day
Model metadata
Abstract base class
in
27. Lookup type that returns results with a case-sensitive end sequence.
endswith
distinct()
contains
==
28. This query deletes all Entry objects with a pub_date year of 2005.
isnull
iteration
Entry.objects.filter(pub_date__year=2005).delete()
startswith
29. 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
class type
none()
Abstract base class
exclude(**kwargs)
30. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
iexact
relationship spanning
values(*fields)
31. Negation operator for Q objects.
~
primary_key
OneToOneField
update(**kwargs)
32. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
endswith
ordered
values_list(*fields)
OneToOneField
33. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
OneToOneField
startswith
related_name
lte
34. A Python "magic method" that returns a unicode "representation" of any object.
ForeignKey
istartswith
Manager methods
__unicode__()
35. This model method is used for updating a ManyToManyField.
add()
db
iexact
save()
36. 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.
get(**kwargs)
iteration
add()
DoesNotExist
37. 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)
exclude(**kwargs)
through argument
many-to-one relationship
38. This query finds all entries with an id greater than 4.
month
select_related()
update(**kwargs)
Entry.objects.filter(id__gt=4)
39. Lookup type that returns results with a case-insensitive end sequence.
delete()
iendswith
year
==
40. 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
endswith
exact
Entry.objects.filter(id__in=[1 - 3 - 4])
41. Used to get a QuerySet for a model. This is called 'objects' by default.
endswith
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
ManyToManyField
Manager
42. A convenience method for looking up an object with the given kwargs - creating one if necessary.
in_bulk(id_list)
order_by(*fields)
get_or_create(**kwargs)
pk
43. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
reverse()
unique
day
44. 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.
model
Proxy model
exists()
many-to-one relationship
45. 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
only(*fields)
MultipleObjectsReturned
exists()
lt
46. Can be used to remove all many-to-many relationships for an instance
contains
clear() method
__unicode__()
distinct()
47. 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.
iregex
Proxy model
aggregate(args - *kwargs)
Multi-table inheritance
48. Fields are specified by these
class attributes
model
exact
__unicode__()
49. 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.
filter(**kwargs)
lte
order_by(*fields)
month
50. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
values(*fields)
update()
pk
ordered