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. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
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.
search
in_bulk(id_list)
Many-to-many relationship to self
id field
3. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
lte
gt
one-to-one relationship
DoesNotExist
4. 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
get_or_create(**kwargs)
through argument
only(*fields)
regex
5. Returns the object matching the given lookup parameters
get(**kwargs)
ManyToManyField
Many-to-many relationship through an intermediate model
range
6. Conjuntion operator for Q objects.
clear() method
class attributes
count()
&
7. 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.
get_absolute_url()
Multi-table inheritance
iteration
gt
8. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
month
==
iendswith
9. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
lt
iteration
ForeignKey
values(*fields)
10. Exception raised by get(**kwargs) if no items match the query.
relationship spanning
blank
reverse()
DoesNotExist
11. The database that will be used if this query is executed now
order_by(*fields)
Many-to-many relationship to self
db
in_bulk(id_list)
12. 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()
&
Q()
gt
13. 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
filter
pk
primary_key
exists()
14. Lookup type that returns results with a case-sensitive end sequence.
dates(field - kind - order='ASC')
filter(**kwargs)
clear() method
endswith
15. The default for this is the name of the child class followed by '_set'.
reverse name
filter(**kwargs)
day
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
16. 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.
get_absolute_url()
id field
istartswith
unique
17. A Q object that encapsulates queries for entries with a question value that starts with 'What' in a case-insensitive fashion.
18. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager methods
ForeignKey
Manager
~
19. Exception raised by get(**kwargs) if more than one item matches the query.
gt
MultipleObjectsReturned
values(*fields)
help_text
20. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
reverse()
month
filter chaining
21. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
relationship spanning
F()
exact
22. Lookup type that finds a case-sensitive regular expression match.
Multi-table inheritance
values_list(*fields)
Entry.objects.filter(pub_date__range=(start_date - end_date))
regex
23. 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
Multi-table inheritance
intermediate models
Entry.objects.filter(pub_date__year=2005).delete()
year
24. 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.
dates(field - kind - order='ASC')
QuerySet
regex
update()
25. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
only(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
isnull
ordered
26. This method immediately deletes the object and has no return value.
null
__unicode__()
delete()
through argument
27. When to run syncdb
lte
get(**kwargs)
when you add new apps to INSTALLED_APPS
relationship spanning
28. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
aggregate(args - *kwargs)
Custom model methods
delete()
29. 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.
choices
Proxy model
week_day
endswith
30. 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
__unicode__()
all()
delete()
in_bulk(id_list)
31. Evaluation happens upon use the "step" parameter of slice syntax - the first time you iterate over it - when pickling or caching results - upon calling repr() - upon calling len() - upon calling list() - upon calling bool()
choices tuple
Entry.objects.filter(pub_date__range=(start_date - end_date))
aggregate(args - *kwargs)
evaluation
32. If this option is True - the field is allowed to be blank. Default is False.
blank
get_or_create(**kwargs)
one-to-one relationship
lt
33. Can be used to remove all many-to-many relationships for an instance
get_absolute_url()
model
pk
clear() method
34. A Python "magic method" that returns a unicode "representation" of any object.
iterator()
endswith
F()
__unicode__()
35. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
36. Lookup type that finds a case-insensitive regular expression match.
none()
iregex
evaluation
year
37. This query uses an F object to increment the pingback count for every entry in the blog.
38. This represents a collection of objects from your database. It can have zero - one or many filters.
blank
values_list(*fields)
reverse()
QuerySet
39. Disjunction operator for Q objects.
week_day
|
save()
default
40. 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.
startswith
none()
help_text
OneToOneField
41. 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.
F()
model
related_name
OneToOneField
42. 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)
__unicode__()
year
gt
43. If True - this field is the primary key for the model.
week_day
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
primary_key
many-to-many relationship
44. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
Custom model methods
month
pickling
choices
45. 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.
Proxy model
order_by(*fields)
class type
delete()
46. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
range
related_name
filter(**kwargs)
pickling
47. If this option is True - Django will store empty values as NULL in the database. Default is False.
order_by(*fields)
Field lookups
null
save()
48. 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.
null
reverse()
&
ForeignKey
49. Lookup type for date/datetime fields that finds an exact day match.
help_text
iexact
range
day
50. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
unique
Entry.objects.filter(pub_date__year=2005).delete()
order_by(*fields)