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. When to run syncdb
when you add new apps to INSTALLED_APPS
istartswith
pickling
null
2. Lookup type that finds a case-sensitive regular expression match.
Q(question__istartswith='What')
pk
regex
year
3. 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
get(**kwargs)
only(*fields)
using(alias)
many-to-many relationship
4. A Python "magic method" that returns a unicode "representation" of any object.
id field
Restrictions on field names
__unicode__()
many-to-one relationship
5. Lookup type that returns results less than a given value.
lt
using(alias)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
related_name
6. Keyword shortcut for looking up an object by primary key.
related_name
delete()
pk
id field
7. 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.
Many-to-many relationship through an intermediate model
update()
clear() method
contains
8. 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
iendswith
unique
exists()
Custom model methods
9. Lookup type that returns results that fall into an inclusive date range.
get_absolute_url()
select_related()
iregex
range
10. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
related_name
in_bulk(id_list)
class attributes
11. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
null
count()
Field lookups
range
12. 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
Entry.objects.filter(pub_date__year=2005).delete()
Proxy model
~
day
13. 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
__unicode__()
many-to-many relationship
related_name
14. 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
ordered
__unicode__()
Q()
15. If this option is True - Django will store empty values as NULL in the database. Default is False.
through argument
iexact
null
select_related()
16. 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.
choices tuple
when you add new apps to INSTALLED_APPS
get_absolute_url()
in_bulk(id_list)
17. Conjuntion operator for Q objects.
Entry.objects.filter(pub_date__year=2005).delete()
only(*fields)
&
when you add new apps to INSTALLED_APPS
18. These methods are intended to do "table-wide" things.
exclude(**kwargs)
Restrictions on field names
none()
Manager methods
19. 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
&
update(**kwargs)
iterator()
==
20. Negation operator for Q objects.
~
clear() method
ManyToManyField
Entry.objects.filter(id__in=[1 - 3 - 4])
21. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
ManyToManyField
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
day
model
22. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
values(*fields)
ordered
exclude(**kwargs)
annotate(args - *kwargs)
23. 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
24. Lookup type that returns results less than or equal to a given value.
Multi-table inheritance
regex
lte
create(**kwargs)
25. Returns the most recent object in the table - by date - using the field_name provided as the date field.
get_or_create(**kwargs)
primary_key
exclude(**kwargs)
latest(field_name=None)
26. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
~
iterator()
save()
27. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
unique
select_related()
get_absolute_url()
isnull
28. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
unique
iendswith
Q()
F()
29. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
blank
exists()
~
30. 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
31. 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
distinct()
annotate(args - *kwargs)
default
through argument
32. 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
iterator()
unique
filter(**kwargs)
all()
33. Lookup type that returns results in a given list.
latest(field_name=None)
all()
in
blank
34. 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.
relationship spanning
pickling
distinct()
gte
35. 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
36. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
values_list(*fields)
id field
distinct()
37. a QuerySet can be sliced - using Python's array-slicing syntax.
defer(*fields)
slicing
values_list(*fields)
QuerySet
38. 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.
Entry.objects.filter(id__gt=4)
values(*fields)
choices
Restrictions on field names
39. 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
40. This model method is used for updating a ManyToManyField.
gte
db
distinct()
add()
41. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
intermediate models
month
primary_key
all()
42. The database that will be used if this query is executed now
db
all()
iendswith
__unicode__()
43. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
exact
related_name
order_by(*fields)
Q()
44. Lookup type that yields a case-insensitive match.
create(**kwargs)
iexact
get_absolute_url()
reverse()
45. 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(**kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Q()
reverse()
46. 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()
~
Custom model methods
evaluation
lte
47. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
all()
related_name
day
Field lookups
48. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Abstract base class
many-to-many relationship
only(*fields)
all()
49. This gives your model metadata.
clear() method
__unicode__()
slicing
Meta class
50. 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.
OneToOneField
Field lookups
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Manager methods