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. 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
pk
intermediate models
class type
Manager methods
2. (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.
all()
QuerySet
Proxy model
Restrictions on field names
3. 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)
F()
distinct()
Q()
4. 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
null
relationship spanning
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
many-to-one relationship
5. Lookup type that returns results with a case-insensitive start sequence.
aggregate(args - *kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Many-to-many relationship through an intermediate model
istartswith
6. Manager method used to retrieve every object in a model.
all()
reverse()
save()
exclude(**kwargs)
7. Can be used to remove all many-to-many relationships for an instance
values_list(*fields)
clear() method
unique
filter
8. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
&
filter(**kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
default
9. 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
in_bulk(id_list)
istartswith
none()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
10. 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
11. If True - the table does not permit duplicate values for this field.
unique
primary_key
lte
get(**kwargs)
12. 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
search
iendswith
lt
defer(*fields)
13. Negation operator for Q objects.
model
get_or_create(**kwargs)
regex
~
14. Lookup type for date/datetime fields that finds an exact day match.
related_name
day
defer(*fields)
choices tuple
15. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
select_related()
filter chaining
contains
16. This gives your model metadata.
null
iexact
Meta class
F()
17. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
ordered
class attributes
year
delete()
18. This model method saves a model instance to the database. This method has no return value.
in_bulk(id_list)
only(*fields)
class type
save()
19. 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.
latest(field_name=None)
&
reverse()
exclude(**kwargs)
20. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
filter(**kwargs)
one-to-one relationship
MultipleObjectsReturned
21. 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
delete()
save()
latest(field_name=None)
update(**kwargs)
22. 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
23. 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
week_day
through argument
__unicode__()
Proxy model
24. 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.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
iregex
Many-to-many relationship through an intermediate model
endswith
25. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
select_related()
&
iterator()
through argument
26. Lookup type that returns results greater than or equal to a given value.
endswith
F()
OneToOneField
gte
27. 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.
endswith
iregex
order_by(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
28. Keyword shortcut for looking up an object by primary key.
pk
Entry.objects.filter(pub_date__range=(start_date - end_date))
dates(field - kind - order='ASC')
ForeignKey
29. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Entry.objects.filter(id__gt=4)
update()
distinct()
~
30. 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.
related_name
~
aggregate(args - *kwargs)
defer(*fields)
31. 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.
filter
many-to-many relationship
Entry.objects.filter(id__in=[1 - 3 - 4])
values_list(*fields)
32. A convenience method for constructing an object and saving it all in one step.
all()
create(**kwargs)
unique
|
33. 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
all()
get(**kwargs)
Manager
annotate(args - *kwargs)
34. Lookup type that returns results with a case-insensitive end sequence.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
iendswith
Many-to-many relationship through an intermediate model
gte
35. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Custom model methods
when you add new apps to INSTALLED_APPS
month
unique
36. This is a criterion that narrow down a QuerySet based on given parameters.
blank
values(*fields)
regex
filter
37. Lookup type that returns results in a given list.
Manager methods
Proxy model
in
iendswith
38. 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.
values(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
ordered
search
39. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
many-to-one relationship
create(**kwargs)
intermediate models
relationship spanning
40. Lookup type that yields a case-insensitive match.
iteration
through argument
iexact
many-to-one relationship
41. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
intermediate models
clear() method
save()
42. Exception raised by get(**kwargs) if no items match the query.
add()
class type
Many-to-many relationship through an intermediate model
DoesNotExist
43. Lookup type that returns results greater than a given value.
|
gt
count()
Custom model methods
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.
slicing
many-to-one relationship
all()
F()
45. To activate your models
Abstract base class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
only(*fields)
dates(field - kind - order='ASC')
46. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
in_bulk(id_list)
count()
model
default
47. This query deletes all Entry objects with a pub_date year of 2005.
relationship spanning
&
gt
Entry.objects.filter(pub_date__year=2005).delete()
48. When to run syncdb
when you add new apps to INSTALLED_APPS
iregex
filter chaining
gte
49. 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.
Field lookups
contains
exact
iteration
50. Lookup type that returns results with a case-sensitive start sequence.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
none()
startswith
unique