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.
slicing
filter(**kwargs)
regex
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
2. Lookup type that yields a case-insensitive match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
iexact
slicing
OneToOneField
3. Lookup type that returns results less than a given value.
update()
exclude(**kwargs)
lt
get_absolute_url()
4. Lookup type that finds a case-sensitive regular expression match.
choices
regex
week_day
default
5. A convenience method for looking up an object with the given kwargs - creating one if necessary.
all()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get_or_create(**kwargs)
DoesNotExist
6. When to run syncdb
when you add new apps to INSTALLED_APPS
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
regex
iexact
7. Conjuntion operator for Q objects.
ForeignKey
&
evaluation
Restrictions on field names
8. 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
order_by(*fields)
MultipleObjectsReturned
class type
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
9. 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.
reverse()
class type
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
order_by(*fields)
10. This query finds all entries with an id in the list [1 - 3 - 4]
week_day
Entry.objects.filter(id__in=[1 - 3 - 4])
order_by(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
11. This field is added automatically - but this behavior can be overridden
id field
choices
many-to-many relationship
ordered
12. 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
Abstract base class
reverse()
delete()
Q(question__istartswith='What')
13. Lookup type that finds a case-insensitive regular expression match.
iregex
exclude(**kwargs)
delete()
order_by(*fields)
14. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
many-to-many relationship
pickling
Multi-table inheritance
15. 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.
gte
pickling
slicing
week_day
16. If True - the table does not permit duplicate values for this field.
Entry.objects.filter(id__gt=4)
unique
~
contains
17. Defines a many-to-many relationship. You use it just like any other Field type: by including it as a class attribute of your model.
year
db
ManyToManyField
in
18. A Python "magic method" that returns a unicode "representation" of any object.
OneToOneField
get_or_create(**kwargs)
__unicode__()
get(**kwargs)
19. 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
search
update(**kwargs)
F()
clear() method
20. Lookup type that tests for inclusion in a case-sensitive fashion.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
isnull
contains
Many-to-many relationship to self
21. 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()
only(*fields)
evaluation
==
gt
22. 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
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
year
none()
primary_key
23. Lookup type that returns results greater than a given value.
class attributes
gt
iendswith
QuerySet
24. Lookup type that returns results with a case-insensitive start sequence.
Custom model methods
Multi-table inheritance
istartswith
get(**kwargs)
25. A convenience method for constructing an object and saving it all in one step.
isnull
primary_key
iteration
create(**kwargs)
26. This method immediately deletes the object and has no return value.
related_name
add()
pickling
delete()
27. (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.
Restrictions on field names
get_absolute_url()
regex
OneToOneField
28. 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
29. 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.
many-to-one relationship
choices tuple
F()
Field lookups
30. 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)
Proxy model
pickling
QuerySet
Model metadata
31. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.filter(pub_date__year=2005).delete()
many-to-many relationship
Q()
default
32. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
related_name
QuerySet
relationship spanning
iterator()
33. 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.
count()
Multi-table inheritance
Entry.objects.filter(pub_date__year=2005).delete()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
34. Lookup type that yields an "exact" match. If you don't provide a lookup type -- that is - if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be of this sort.
search
exact
iterator()
Manager
35. 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
order_by(*fields)
get_absolute_url()
defer(*fields)
in
36. 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.
exact
filter(**kwargs)
many-to-one relationship
order_by(*fields)
37. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Multi-table inheritance
ordered
save()
exact
38. 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.
Many-to-many relationship to self
Entry.objects.filter(pub_date__year=2005).delete()
pickling
exclude(**kwargs)
39. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
ordered
contains
distinct()
iteration
40. Returns the object matching the given lookup parameters
intermediate models
Manager methods
filter(**kwargs)
get(**kwargs)
41. If True - this field is the primary key for the model.
primary_key
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
order_by(*fields)
&
42. 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
43. Can be used to remove all many-to-many relationships for an instance
month
class type
clear() method
Entry.objects.filter(pub_date__range=(start_date - end_date))
44. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
exclude(**kwargs)
pk
Abstract base class
45. Returns a new QuerySet containing objects that match the given lookup parameters.
Entry.objects.filter(pub_date__year=2005).delete()
filter(**kwargs)
many-to-many relationship
values_list(*fields)
46. Exception raised by get(**kwargs) if no items match the query.
Entry.objects.filter(pub_date__year=2005).delete()
many-to-one relationship
DoesNotExist
gt
47. 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.
class attributes
choices tuple
ForeignKey
through argument
48. Disjunction operator for Q objects.
Manager
get_or_create(**kwargs)
all()
|
49. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
filter
==
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Custom model methods
50. This gives your model metadata.
week_day
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Meta class
filter chaining