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. Can be used to remove all many-to-many relationships for an instance
lte
clear() method
choices tuple
Model metadata
2. This query finds all entries with an id greater than 4.
Entry.objects.filter(id__gt=4)
Custom model methods
values_list(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
3. 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.
|
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
order_by(*fields)
4. 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.
reverse name
==
get_absolute_url()
filter
5. 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
Field lookups
day
exact
class type
6. Specifies the model that will be used to govern the many-to-many relationship. You can then put extra fields on the intermediate model. The intermediate model is associated with the ManyToManyField using this to point to the model that will act as an
through argument
Entry.objects.filter(pub_date__year=2005).delete()
in_bulk(id_list)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
7. Lookup type that returns results greater than or equal to a given value.
month
gte
search
relationship spanning
8. 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
Restrictions on field names
iexact
dates(field - kind - order='ASC')
9. Negation operator for Q objects.
~
exact
values_list(*fields)
unique
10. Lookup type for date/datetime fields that finds a 'day of the week' match.
Model metadata
defer(*fields)
many-to-many relationship
week_day
11. 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.
search
range
Multi-table inheritance
using(alias)
12. This query deletes all Entry objects with a pub_date year of 2005.
evaluation
Entry.objects.filter(pub_date__year=2005).delete()
pk
iregex
13. (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.
choices tuple
Restrictions on field names
Field lookups
in_bulk(id_list)
14. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
aggregate(args - *kwargs)
in_bulk(id_list)
month
iteration
15. Lookup type that finds a case-sensitive regular expression match.
reverse()
Many-to-many relationship through an intermediate model
regex
clear() method
16. Lookup type that tests for inclusion in a case-sensitive fashion.
many-to-one relationship
contains
filter(**kwargs)
update(**kwargs)
17. This sets a field to a particular value for all the objects in a QuerySet. You can only set non-relation fields and ForeignKey fields using this method.
==
model
ForeignKey
update()
18. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
all()
one-to-one relationship
in
Multi-table inheritance
19. Lookup type that finds a case-insensitive regular expression match.
iregex
filter
exact
startswith
20. Manager method used to retrieve every object in a model.
startswith
delete()
all()
Manager methods
21. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
none()
related_name
Manager methods
Field lookups
22. 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.
==
relationship spanning
pickling
Entry.objects.filter(id__in=[1 - 3 - 4])
23. Lookup type that returns results less than a given value.
lt
ForeignKey
Q(question__istartswith='What')
Q()
24. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
filter chaining
month
Entry.objects.filter(pub_date__year=2005).delete()
25. 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.
evaluation
get_or_create(**kwargs)
defer(*fields)
Multi-table inheritance
26. The database that will be used if this query is executed now
get_or_create(**kwargs)
delete()
OneToOneField
db
27. 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
intermediate models
select_related()
annotate(args - *kwargs)
iteration
28. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Q(question__istartswith='What')
filter(**kwargs)
add()
only(*fields)
29. If this option is True - the field is allowed to be blank. Default is False.
blank
ForeignKey
&
==
30. If this option is True - Django will store empty values as NULL in the database. Default is False.
contains
null
Field lookups
year
31. 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
32. 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.
lt
get(**kwargs)
exact
clear() method
33. The default for this is the name of the child class followed by '_set'.
distinct()
one-to-one relationship
gte
reverse name
34. 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
primary_key
clear() method
ordered
35. Fields are specified by these
aggregate(args - *kwargs)
class attributes
relationship spanning
|
36. 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.
ForeignKey
create(**kwargs)
exact
OneToOneField
37. This query finds all entries between a start date of start_date and an end date of end_date.
exact
many-to-one relationship
iterator()
Entry.objects.filter(pub_date__range=(start_date - end_date))
38. 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
39. Lookup type that returns results greater than a given value.
ManyToManyField
model
order_by(*fields)
gt
40. Lookup type that returns results with a case-insensitive end sequence.
endswith
isnull
count()
iendswith
41. This gives your model metadata.
search
Meta class
gt
Restrictions on field names
42. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
through argument
annotate(args - *kwargs)
model
43. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
Q()
create(**kwargs)
save()
help_text
44. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
isnull
values(*fields)
Entry.objects.filter(id__in=[1 - 3 - 4])
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
45. 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.
delete()
get(**kwargs)
in
exact
46. Lookup type that returns results in a given list.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
in
reverse()
model
47. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Custom model methods
Many-to-many relationship to self
all()
ordered
48. 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()
using(alias)
through argument
endswith
49. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
exact
year
Field lookups
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
50. 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.
aggregate(args - *kwargs)
intermediate models
DoesNotExist
annotate(args - *kwargs)