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. 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
iexact
create(**kwargs)
id field
2. 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
exists()
values(*fields)
in
reverse name
3. Fields are specified by these
choices tuple
iteration
istartswith
class attributes
4. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
range
isnull
get_absolute_url()
Entry.objects.filter(pub_date__year=2005).delete()
5. 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.
istartswith
Many-to-many relationship to self
all()
Model metadata
6. Lookup type that yields a case-insensitive match.
choices tuple
db
reverse()
iexact
7. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
iendswith
update()
Abstract base class
8. Negation operator for Q objects.
~
values(*fields)
month
|
9. 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.
only(*fields)
search
Many-to-many relationship through an intermediate model
annotate(args - *kwargs)
10. 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.
year
get(**kwargs)
using(alias)
add()
11. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
12. Returns the object matching the given lookup parameters
get(**kwargs)
__unicode__()
Abstract base class
one-to-one relationship
13. 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.
day
regex
using(alias)
Entry.objects.filter(id__in=[1 - 3 - 4])
14. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
one-to-one relationship
db
year
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
15. 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
blank
istartswith
default
class type
16. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
relationship spanning
Q()
default
17. 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
18. This field is added automatically - but this behavior can be overridden
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
id field
many-to-many relationship
pickling
19. 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
iendswith
only(*fields)
filter(**kwargs)
choices
20. 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.
evaluation
pickling
update(**kwargs)
all()
21. 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.
values_list(*fields)
isnull
blank
OneToOneField
22. A convenience method for constructing an object and saving it all in one step.
help_text
create(**kwargs)
save()
order_by(*fields)
23. Lookup type that returns results less than a given value.
regex
db
lt
in_bulk(id_list)
24. Lookup type that returns results with a case-sensitive end sequence.
endswith
class type
pickling
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
25. 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
ForeignKey
in_bulk(id_list)
none()
unique
26. The default for this is the name of the child class followed by '_set'.
Entry.objects.filter(pub_date__range=(start_date - end_date))
blank
primary_key
reverse name
27. This gives your model metadata.
select_related()
Meta class
endswith
lte
28. 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.
filter(**kwargs)
clear() method
delete()
blank
29. Keyword shortcut for looking up an object by primary key.
help_text
&
pk
Restrictions on field names
30. Lookup type that returns results greater than a given value.
using(alias)
related_name
gt
order_by(*fields)
31. 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.
Abstract base class
values(*fields)
reverse()
Entry.objects.filter(pub_date__year=2005).delete()
32. Returns the most recent object in the table - by date - using the field_name provided as the date field.
ordered
istartswith
year
latest(field_name=None)
33. Lookup type that finds a case-sensitive regular expression match.
in_bulk(id_list)
regex
Entry.objects.filter(id__in=[1 - 3 - 4])
contains
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.
latest(field_name=None)
save()
exact
Model metadata
35. a QuerySet can be sliced - using Python's array-slicing syntax.
iexact
slicing
class attributes
gt
36. 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.
using(alias)
Multi-table inheritance
values_list(*fields)
many-to-many relationship
37. This model method saves a model instance to the database. This method has no return value.
save()
clear() method
~
in
38. Can be used to remove all many-to-many relationships for an instance
endswith
clear() method
Manager
iteration
39. Lookup type that finds a case-insensitive regular expression match.
Q()
week_day
ForeignKey
iregex
40. When to run syncdb
slicing
choices tuple
when you add new apps to INSTALLED_APPS
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
41. Lookup type that returns results with a case-insensitive end sequence.
regex
iendswith
Many-to-many relationship through an intermediate model
defer(*fields)
42. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
exists()
latest(field_name=None)
&
month
43. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
blank
iteration
evaluation
distinct()
44. 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
Restrictions on field names
F()
Meta class
__unicode__()
45. Lookup type for date/datetime fields that finds an exact day match.
&
id field
day
evaluation
46. Used to get a QuerySet for a model. This is called 'objects' by default.
help_text
ManyToManyField
Manager
get_absolute_url()
47. Disjunction operator for Q objects.
|
Field lookups
Multi-table inheritance
reverse name
48. Lookup type that returns results with a case-insensitive start sequence.
ManyToManyField
select_related()
Multi-table inheritance
istartswith
49. 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.
get(**kwargs)
choices
istartswith
isnull
50. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
save()
MultipleObjectsReturned
regex
one-to-one relationship