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 Python "magic method" that returns a unicode "representation" of any object.
iterator()
__unicode__()
|
db
2. If this option is True - Django will store empty values as NULL in the database. Default is False.
when you add new apps to INSTALLED_APPS
null
week_day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
3. 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.
defer(*fields)
contains
default
4. 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
all()
values(*fields)
update()
help_text
5. Lookup type that returns results less than or equal to a given value.
Many-to-many relationship through an intermediate model
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
get(**kwargs)
lte
6. 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
Field lookups
F()
month
7. 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.
exact
get_or_create(**kwargs)
startswith
select_related()
8. Manager method used to retrieve every object in a model.
blank
using(alias)
all()
reverse name
9. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
get_absolute_url()
gt
clear() method
ordered
10. 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.
through argument
select_related()
save()
values_list(*fields)
11. This model method is used for updating a ManyToManyField.
null
add()
many-to-one relationship
month
12. This query finds all entries with an id in the list [1 - 3 - 4]
reverse name
Proxy model
endswith
Entry.objects.filter(id__in=[1 - 3 - 4])
13. Lookup type that returns results less than a given value.
slicing
order_by(*fields)
lt
update(**kwargs)
14. Lookup type that returns results with a case-sensitive start sequence.
choices
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
startswith
one-to-one relationship
15. 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()
distinct()
isnull
values(*fields)
16. Exception raised by get(**kwargs) if no items match the query.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
DoesNotExist
gte
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
17. Lookup type that returns results with a case-insensitive end sequence.
defer(*fields)
primary_key
iendswith
order_by(*fields)
18. This query finds all entries between a start date of start_date and an end date of end_date.
intermediate models
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Entry.objects.filter(pub_date__range=(start_date - end_date))
null
19. Lookup type that returns results greater than or equal to a given value.
aggregate(args - *kwargs)
order_by(*fields)
gte
DoesNotExist
20. The database that will be used if this query is executed now
through argument
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
range
db
21. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
get(**kwargs)
Many-to-many relationship to self
update(**kwargs)
values(*fields)
22. These add custom "row-level" functionality to your objects. These act on a particular model instance.
get(**kwargs)
values_list(*fields)
through argument
Custom model methods
23. Keyword shortcut for looking up an object by primary key.
in_bulk(id_list)
lt
OneToOneField
pk
24. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
filter
only(*fields)
update(**kwargs)
25. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
relationship spanning
lt
exclude(**kwargs)
OneToOneField
26. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
Entry.objects.filter(pub_date__range=(start_date - end_date))
Manager methods
year
latest(field_name=None)
27. This field is added automatically - but this behavior can be overridden
Field lookups
class type
Many-to-many relationship through an intermediate model
id field
28. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire
~
endswith
day
iterator()
29. (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.
DoesNotExist
Many-to-many relationship through an intermediate model
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Restrictions on field names
30. 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
31. 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
intermediate models
get(**kwargs)
order_by(*fields)
|
32. 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.
reverse name
QuerySet
&
order_by(*fields)
33. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
filter
lte
ordered
34. To activate your models
get_absolute_url()
Q()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
==
35. Exception raised by get(**kwargs) if more than one item matches the query.
Proxy model
exclude(**kwargs)
MultipleObjectsReturned
values_list(*fields)
36. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
regex
~
values_list(*fields)
37. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
==
iexact
one-to-one relationship
F()
38. Lookup type that returns results in a given list.
in
|
intermediate models
choices tuple
39. Negation operator for Q objects.
id field
~
day
using(alias)
40. 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.
year
choices tuple
Q()
values_list(*fields)
41. 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
__unicode__()
iregex
isnull
42. 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.
delete()
Many-to-many relationship to self
MultipleObjectsReturned
Entry.objects.filter(pub_date__range=(start_date - end_date))
43. This tells Django how to calculate the URL for an object. Django uses this in its admin interface - and any time it needs to figure out a URL for an object.
many-to-many relationship
get_absolute_url()
class attributes
~
44. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
QuerySet
clear() method
gt
45. This represents a collection of objects from your database. It can have zero - one or many filters.
id field
month
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
QuerySet
46. 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
&
delete()
QuerySet
select_related()
47. If True - this field is the primary key for the model.
primary_key
filter chaining
exclude(**kwargs)
update()
48. This model method saves a model instance to the database. This method has no return value.
only(*fields)
iexact
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
save()
49. If this option is True - the field is allowed to be blank. Default is False.
lt
blank
using(alias)
isnull
50. 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.
week_day
DoesNotExist
Many-to-many relationship through an intermediate model
month