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. If True - this field is the primary key for the model.
primary_key
update()
reverse()
reverse name
2. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
week_day
db
related_name
3. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
Many-to-many relationship to self
Restrictions on field names
year
values_list(*fields)
4. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
reverse name
one-to-one relationship
order_by(*fields)
filter(**kwargs)
5. A Python "magic method" that returns a unicode "representation" of any object.
many-to-one relationship
choices tuple
save()
__unicode__()
6. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
MultipleObjectsReturned
latest(field_name=None)
filter(**kwargs)
7. Manager method used to retrieve every object in a model.
only(*fields)
all()
iregex
Field lookups
8. 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
model
defer(*fields)
exists()
default
9. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
OneToOneField
slicing
year
10. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary
==
endswith
class attributes
only(*fields)
11. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Proxy model
filter(**kwargs)
Custom model methods
Multi-table inheritance
12. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode
select_related()
month
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Abstract base class
13. 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.
search
count()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
reverse()
14. 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
annotate(args - *kwargs)
choices tuple
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
15. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
all()
count()
when you add new apps to INSTALLED_APPS
lt
16. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
save()
many-to-one relationship
in
17. 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.
|
using(alias)
Restrictions on field names
Entry.objects.filter(pub_date__range=(start_date - end_date))
18. Lookup type that returns results with a case-insensitive end sequence.
filter(**kwargs)
istartswith
iendswith
evaluation
19. Lookup type for date/datetime fields that finds an exact day match.
get_or_create(**kwargs)
day
QuerySet
~
20. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
regex
Field lookups
Entry.objects.filter(pub_date__range=(start_date - end_date))
isnull
21. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
select_related()
primary_key
exclude(**kwargs)
many-to-many relationship
22. Negation operator for Q objects.
gt
~
pickling
latest(field_name=None)
23. The default for this is the name of the child class followed by '_set'.
reverse name
dates(field - kind - order='ASC')
lt
relationship spanning
24. If this option is True - Django will store empty values as NULL in the database. Default is False.
get_absolute_url()
latest(field_name=None)
Proxy model
null
25. Lookup type for date/datetime fields that finds a 'day of the week' match.
blank
none()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
26. 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
aggregate(args - *kwargs)
in_bulk(id_list)
&
27. 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.
when you add new apps to INSTALLED_APPS
pickling
istartswith
Restrictions on field names
28. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
delete()
istartswith
filter(**kwargs)
29. 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
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
Custom model methods
all()
isnull
null
31. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
QuerySet
primary_key
Restrictions on field names
32. Lookup type that returns results with a case-sensitive start sequence.
reverse()
ordered
get_absolute_url()
startswith
33. 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.
iteration
Many-to-many relationship through an intermediate model
get(**kwargs)
get_or_create(**kwargs)
34. A convenience method for constructing an object and saving it all in one step.
Many-to-many relationship through an intermediate model
only(*fields)
create(**kwargs)
lt
35. Conjuntion operator for Q objects.
endswith
get(**kwargs)
Field lookups
&
36. 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.
Custom model methods
slicing
month
Multi-table inheritance
37. 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()
evaluation
intermediate models
QuerySet
default
38. Lookup type that returns results that fall into an inclusive date range.
range
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in_bulk(id_list)
gte
39. 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
get_or_create(**kwargs)
distinct()
year
update(**kwargs)
40. 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.
clear() method
Manager methods
get_absolute_url()
Entry.objects.filter(id__in=[1 - 3 - 4])
41. 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.
~
filter chaining
Entry.objects.filter(id__gt=4)
update()
42. a QuerySet can be sliced - using Python's array-slicing syntax.
Entry.objects.filter(pub_date__range=(start_date - end_date))
iendswith
iregex
slicing
43. 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
44. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
through argument
ordered
count()
Entry.objects.filter(id__in=[1 - 3 - 4])
45. This field is added automatically - but this behavior can be overridden
id field
choices tuple
pickling
lt
46. Fields are specified by these
regex
class attributes
using(alias)
null
47. 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.
model
distinct()
exclude(**kwargs)
Q()
48. Lookup type that returns results with a case-insensitive start sequence.
Q()
istartswith
Abstract base class
null
49. 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
all()
filter
iterator()
filter(**kwargs)
50. When to run syncdb
when you add new apps to INSTALLED_APPS
DoesNotExist
intermediate models
get(**kwargs)
Sorry!:) No result found.
Can you answer 50 questions in 15 minutes?
Let me suggest you:
Browse all subjects
Browse all tests
Most popular tests
Major Subjects
Tests & Exams
AP
CLEP
DSST
GRE
SAT
GMAT
Certifications
CISSP go to https://www.isc2.org/
PMP
ITIL
RHCE
MCTS
More...
IT Skills
Android Programming
Data Modeling
Objective C Programming
Basic Python Programming
Adobe Illustrator
More...
Business Skills
Advertising Techniques
Business Accounting Basics
Business Strategy
Human Resource Management
Marketing Basics
More...
Soft Skills
Body Language
People Skills
Public Speaking
Persuasion
Job Hunting And Resumes
More...
Vocabulary
GRE Vocab
SAT Vocab
TOEFL Essential Vocab
Basic English Words For All
Global Words You Should Know
Business English
More...
Languages
AP German Vocab
AP Latin Vocab
SAT Subject Test: French
Italian Survival
Norwegian Survival
More...
Engineering
Audio Engineering
Computer Science Engineering
Aerospace Engineering
Chemical Engineering
Structural Engineering
More...
Health Sciences
Basic Nursing Skills
Health Science Language Fundamentals
Veterinary Technology Medical Language
Cardiology
Clinical Surgery
More...
English
Grammar Fundamentals
Literary And Rhetorical Vocab
Elements Of Style Vocab
Introduction To English Major
Complete Advanced Sentences
Literature
Homonyms
More...
Math
Algebra Formulas
Basic Arithmetic: Measurements
Metric Conversions
Geometric Properties
Important Math Facts
Number Sense Vocab
Business Math
More...
Other Major Subjects
Science
Economics
History
Law
Performing-arts
Cooking
Logic & Reasoning
Trivia
Browse all subjects
Browse all tests
Most popular tests