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 yields a case-insensitive match.
iexact
filter(**kwargs)
year
MultipleObjectsReturned
2. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
aggregate(args - *kwargs)
iteration
~
3. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
iendswith
in
filter(**kwargs)
4. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
all()
Meta class
clear() method
Many-to-many relationship through an intermediate model
5. 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
6. Manager method used to retrieve every object in a model.
all()
class attributes
Restrictions on field names
iendswith
7. Lookup type that returns results with a case-sensitive start sequence.
search
dates(field - kind - order='ASC')
startswith
QuerySet
8. 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.
annotate(args - *kwargs)
many-to-many relationship
get_or_create(**kwargs)
many-to-one relationship
9. 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
lt
month
Proxy model
10. 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
one-to-one relationship
latest(field_name=None)
choices tuple
11. If this option is True - Django will store empty values as NULL in the database. Default is False.
month
only(*fields)
through argument
null
12. Exception raised by get(**kwargs) if no items match the query.
&
gt
update(**kwargs)
DoesNotExist
13. A Python "magic method" that returns a unicode "representation" of any object.
add()
none()
__unicode__()
choices tuple
14. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.
Entry.objects.filter(pub_date__year=2005).delete()
reverse()
get_or_create(**kwargs)
get(**kwargs)
15. Can be used to remove all many-to-many relationships for an instance
clear() method
count()
get_or_create(**kwargs)
pickling
16. a QuerySet can be sliced - using Python's array-slicing syntax.
iterator()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
day
slicing
17. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
choices tuple
==
iteration
gte
18. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Entry.objects.filter(pub_date__year=2005).delete()
many-to-many relationship
filter(**kwargs)
get(**kwargs)
19. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
relationship spanning
Entry.objects.filter(pub_date__range=(start_date - end_date))
Restrictions on field names
distinct()
20. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
month
related_name
filter(**kwargs)
using(alias)
21. (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.
Custom model methods
Restrictions on field names
exists()
contains
22. 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
filter(**kwargs)
OneToOneField
filter(**kwargs)
23. This method immediately deletes the object and has no return value.
choices tuple
Custom model methods
delete()
istartswith
24. 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
only(*fields)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
choices
Many-to-many relationship to self
25. Lookup type that returns results in a given list.
get_or_create(**kwargs)
in
choices
in_bulk(id_list)
26. 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
27. 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.
slicing
__unicode__()
evaluation
delete()
28. Keyword shortcut for looking up an object by primary key.
pk
search
__unicode__()
class attributes
29. This model method is used for updating a ManyToManyField.
dates(field - kind - order='ASC')
values(*fields)
add()
~
30. 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.
dates(field - kind - order='ASC')
iteration
Multi-table inheritance
latest(field_name=None)
31. The default for this is the name of the child class followed by '_set'.
defer(*fields)
clear() method
Manager methods
reverse name
32. 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
choices
defer(*fields)
iteration
Many-to-many relationship through an intermediate model
33. 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.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
delete()
values_list(*fields)
gt
34. When to run syncdb
Abstract base class
exists()
when you add new apps to INSTALLED_APPS
distinct()
35. Negation operator for Q objects.
~
Custom model methods
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
endswith
36. 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)
when you add new apps to INSTALLED_APPS
get(**kwargs)
Model metadata
intermediate models
37. 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.
values(*fields)
id field
using(alias)
Entry.objects.filter(id__gt=4)
38. 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.
ManyToManyField
get(**kwargs)
clear() method
model
39. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
40. These methods are intended to do "table-wide" things.
reverse()
Manager methods
range
istartswith
41. 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
id field
Restrictions on field names
exists()
QuerySet
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()
endswith
DoesNotExist
in_bulk(id_list)
evaluation
43. The database that will be used if this query is executed now
db
clear() method
lte
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
44. This represents a collection of objects from your database. It can have zero - one or many filters.
values_list(*fields)
QuerySet
month
range
45. Lookup type that returns results greater than a given value.
Q()
gt
using(alias)
many-to-one relationship
46. Defines a one-to-one relationship. You use it just like any other Field type: by including it as a class attribute of your model.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
related_name
update()
OneToOneField
47. Lookup type that returns results with a case-sensitive end sequence.
iteration
related_name
choices
endswith
48. 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.
Entry.objects.filter(id__gt=4)
all()
in_bulk(id_list)
year
49. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
db
MultipleObjectsReturned
reverse()
year
50. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
QuerySet
help_text
OneToOneField