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. 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.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
many-to-one relationship
default
intermediate models
2. 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
filter
Q(question__istartswith='What')
distinct()
3. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
ordered
year
filter chaining
pickling
4. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
reverse name
delete()
null
5. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Multi-table inheritance
6. 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
relationship spanning
endswith
pk
Model metadata
7. This model method is used for updating a ManyToManyField.
add()
help_text
dates(field - kind - order='ASC')
exists()
8. Lookup type that returns results greater than or equal to a given value.
isnull
iteration
gte
related_name
9. 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
regex
Q()
Proxy model
create(**kwargs)
10. 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()
Meta class
Abstract base class
Entry.objects.filter(pub_date__year=2005).delete()
11. Keyword shortcut for looking up an object by primary key.
through argument
get(**kwargs)
delete()
pk
12. The default for this is the name of the child class followed by '_set'.
intermediate models
values_list(*fields)
reverse name
one-to-one relationship
13. Manager method used to retrieve every object in a model.
all()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Many-to-many relationship through an intermediate model
latest(field_name=None)
14. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
help_text
aggregate(args - *kwargs)
endswith
model
15. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
Many-to-many relationship to self
Model metadata
in_bulk(id_list)
latest(field_name=None)
16. 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()
F()
contains
intermediate models
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. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
all()
using(alias)
day
19. 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.
many-to-many relationship
startswith
Q()
null
20. If this option is True - the field is allowed to be blank. Default is False.
exclude(**kwargs)
iregex
blank
iteration
21. 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.
lte
choices tuple
pk
db
22. 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.
distinct()
get(**kwargs)
range
ForeignKey
23. This query finds all entries between a start date of start_date and an end date of end_date.
pk
Entry.objects.filter(pub_date__range=(start_date - end_date))
isnull
evaluation
24. Lookup type that returns results with a case-sensitive start sequence.
dates(field - kind - order='ASC')
startswith
search
all()
25. A convenience method for constructing an object and saving it all in one step.
gt
id field
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
create(**kwargs)
26. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
many-to-many relationship
all()
filter(**kwargs)
==
27. This query deletes all Entry objects with a pub_date year of 2005.
save()
~
iexact
Entry.objects.filter(pub_date__year=2005).delete()
28. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
Entry.objects.filter(pub_date__year=2005).delete()
count()
db
29. 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()
get(**kwargs)
get_absolute_url()
Field lookups
30. Returns the object matching the given lookup parameters
choices tuple
get(**kwargs)
week_day
save()
31. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
slicing
distinct()
range
null
32. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
startswith
iteration
lt
33. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
week_day
slicing
count()
get(**kwargs)
34. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
iterator()
Field lookups
Entry.objects.filter(pub_date__range=(start_date - end_date))
35. 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
lt
pickling
exists()
create(**kwargs)
36. 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
37. 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
OneToOneField
|
defer(*fields)
all()
38. 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.
evaluation
using(alias)
lt
select_related()
39. 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.
regex
count()
exact
iendswith
40. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
Manager methods
F()
select_related()
41. 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
values(*fields)
Entry.objects.filter(pub_date__year=2005).delete()
blank
42. Lookup type that returns results less than or equal to a given value.
lte
Meta class
gt
distinct()
43. Lookup type that returns results with a case-insensitive start sequence.
unique
all()
gt
istartswith
44. (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
class attributes
all()
year
45. Lookup type for date/datetime fields that finds an exact day match.
delete()
choices tuple
day
QuerySet
46. 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
many-to-one relationship
range
annotate(args - *kwargs)
47. This method immediately deletes the object and has no return value.
Field lookups
delete()
pickling
intermediate models
48. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
pickling
Q(question__istartswith='What')
id field
49. Conjuntion operator for Q objects.
evaluation
&
DoesNotExist
pickling
50. Used to get a QuerySet for a model. This is called 'objects' by default.
Custom model methods
contains
Manager
Many-to-many relationship to self