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 model method saves a model instance to the database. This method has no return value.
defer(*fields)
get(**kwargs)
all()
save()
2. Fields are specified by these
Many-to-many relationship through an intermediate model
intermediate models
class attributes
model
3. 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)
Multi-table inheritance
id field
filter(**kwargs)
4. 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.
get(**kwargs)
distinct()
in_bulk(id_list)
one-to-one relationship
5. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
count()
DoesNotExist
6. This gives your model metadata.
isnull
QuerySet
Meta class
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
7. 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
QuerySet
Many-to-many relationship to self
count()
8. Lookup type that returns results with a case-insensitive end sequence.
iendswith
id field
week_day
lte
9. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
model
Entry.objects.filter(id__in=[1 - 3 - 4])
month
10. Disjunction operator for Q objects.
|
one-to-one relationship
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
==
11. 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(id__gt=4)
filter(**kwargs)
==
many-to-one relationship
12. Exception raised by get(**kwargs) if more than one item matches the query.
intermediate models
istartswith
MultipleObjectsReturned
class type
13. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Abstract base class
annotate(args - *kwargs)
one-to-one relationship
filter chaining
14. Lookup type that returns results with a case-sensitive end sequence.
ManyToManyField
evaluation
endswith
update(**kwargs)
15. A convenience method for looking up an object with the given kwargs - creating one if necessary.
day
get_or_create(**kwargs)
ManyToManyField
choices
16. 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.
order_by(*fields)
regex
filter
ManyToManyField
17. This query finds all entries with an id greater than 4.
ManyToManyField
Proxy model
Entry.objects.filter(id__gt=4)
regex
18. Returns the object matching the given lookup parameters
OneToOneField
get(**kwargs)
values(*fields)
pk
19. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
endswith
==
update(**kwargs)
distinct()
20. When to run syncdb
when you add new apps to INSTALLED_APPS
using(alias)
null
delete()
21. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
Abstract base class
save()
year
day
22. 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.
iexact
relationship spanning
lte
search
23. Adds to each object in the QuerySet with the provided list of aggregate values (averages - sums - etc) that have been computed over the objects that are related to the objects in the QuerySet. Each argument to this is content that will be added to ea
gt
|
annotate(args - *kwargs)
primary_key
24. 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
Proxy model
Field lookups
class attributes
Entry.objects.filter(id__gt=4)
25. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
clear() method
isnull
range
26. Lookup type that yields a case-insensitive match.
iterator()
pk
iexact
Multi-table inheritance
27. If True - the table does not permit duplicate values for this field.
Restrictions on field names
get_absolute_url()
unique
many-to-one relationship
28. 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')
Entry.objects.filter(pub_date__year=2005).delete()
db
Entry.objects.filter(pub_date__range=(start_date - end_date))
29. 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.
create(**kwargs)
aggregate(args - *kwargs)
delete()
iexact
30. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
ordered
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
startswith
31. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
lt
select_related()
lte
32. 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.
update()
filter(**kwargs)
year
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
33. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
Entry.objects.filter(pub_date__range=(start_date - end_date))
filter(**kwargs)
pickling
exact
34. 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.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
save()
OneToOneField
Many-to-many relationship to self
35. These are "anything that's not a field" - such as ordering options (ordering) - database table name (db_table) - or human-readable singular and plural names (verbose_name and verbose_name_plural)
choices
values_list(*fields)
exact
Model metadata
36. 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.
search
aggregate(args - *kwargs)
filter chaining
db
37. 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.
slicing
&
when you add new apps to INSTALLED_APPS
pickling
38. A Python "magic method" that returns a unicode "representation" of any object.
get_absolute_url()
filter(**kwargs)
__unicode__()
one-to-one relationship
39. This model method is used for updating a ManyToManyField.
Entry.objects.filter(id__gt=4)
when you add new apps to INSTALLED_APPS
MultipleObjectsReturned
add()
40. (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
delete()
filter
Restrictions on field names
41. This method immediately deletes the object and has no return value.
range
get(**kwargs)
class type
delete()
42. 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
only(*fields)
year
Meta class
values(*fields)
43. Conjuntion operator for Q objects.
&
Field lookups
F()
many-to-many relationship
44. 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
update(**kwargs)
iregex
values_list(*fields)
many-to-many relationship
45. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
relationship spanning
month
Multi-table inheritance
exclude(**kwargs)
46. Negation operator for Q objects.
delete()
Entry.objects.filter(pub_date__year=2005).delete()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
~
47. 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.
pickling
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Multi-table inheritance
Abstract base class
48. These add custom "row-level" functionality to your objects. These act on a particular model instance.
all()
Custom model methods
Abstract base class
many-to-one relationship
49. Lookup type for date/datetime fields that finds an exact day match.
ForeignKey
Multi-table inheritance
contains
day
50. Used to get a QuerySet for a model. This is called 'objects' by default.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
reverse()
Abstract base class
Manager
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