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. Lookup type that returns results in a given list.
in
Manager methods
get_or_create(**kwargs)
gte
2. Returns the most recent object in the table - by date - using the field_name provided as the date field.
update(**kwargs)
latest(field_name=None)
isnull
istartswith
3. This represents a collection of objects from your database. It can have zero - one or many filters.
lte
QuerySet
iexact
regex
4. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
reverse()
slicing
blank
5. 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
help_text
annotate(args - *kwargs)
iexact
month
6. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
Field lookups
Restrictions on field names
pk
count()
7. A convenience method for looking up an object with the given kwargs - creating one if necessary.
clear() method
get(**kwargs)
get_or_create(**kwargs)
none()
8. This query finds all entries with an id greater than 4.
none()
Entry.objects.filter(id__gt=4)
gte
Proxy model
9. 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()
&
filter(**kwargs)
evaluation
filter chaining
10. 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
range
model
defer(*fields)
MultipleObjectsReturned
11. This method immediately deletes the object and has no return value.
delete()
none()
class attributes
primary_key
12. Lookup type that finds a case-insensitive regular expression match.
exists()
add()
iregex
Model metadata
13. A convenience method for constructing an object and saving it all in one step.
in_bulk(id_list)
Entry.objects.filter(id__gt=4)
gte
create(**kwargs)
14. 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()
id field
default
QuerySet
15. 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
id field
intermediate models
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
many-to-many relationship
16. 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_or_create(**kwargs)
update()
OneToOneField
in_bulk(id_list)
17. This model method saves a model instance to the database. This method has no return value.
only(*fields)
in_bulk(id_list)
save()
F()
18. 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.
many-to-one relationship
in
none()
blank
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.
Q()
all()
~
values(*fields)
20. 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.
many-to-many relationship
isnull
db
Multi-table inheritance
21. 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.
choices
class type
related_name
search
22. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
default
reverse()
filter(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
23. Lookup type that returns results with a case-sensitive end sequence.
exact
~
endswith
get(**kwargs)
24. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
25. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Many-to-many relationship through an intermediate model
ordered
none()
QuerySet
26. 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
many-to-many relationship
==
year
select_related()
27. Lookup type that returns results that fall into an inclusive date range.
through argument
Proxy model
primary_key
range
28. 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()
DoesNotExist
pk
related_name
29. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
all()
Custom model methods
distinct()
when you add new apps to INSTALLED_APPS
30. 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.
values(*fields)
MultipleObjectsReturned
delete()
choices
31. Exception raised by get(**kwargs) if more than one item matches the query.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
MultipleObjectsReturned
defer(*fields)
iteration
32. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Custom model methods
QuerySet
month
istartswith
33. 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.
choices tuple
slicing
save()
Field lookups
34. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
save()
exact
iexact
==
35. 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
primary_key
model
|
36. This object allows you to compare the value of a model field with another field on the same model. Django supports the use of addition - subtraction - multiplication - division and modulo arithmetic with these objects - both with constants and with o
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
F()
regex
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
37. Manager method used to retrieve every object in a model.
help_text
Manager methods
Custom model methods
all()
38. 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.
annotate(args - *kwargs)
lt
default
help_text
39. To activate your models
endswith
db
in
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
40. Lookup type for date/datetime fields that finds an exact day match.
values(*fields)
day
default
filter
41. If this option is True - Django will store empty values as NULL in the database. Default is False.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
update()
intermediate models
null
42. Exception raised by get(**kwargs) if no items match the query.
delete()
DoesNotExist
pk
Proxy model
43. Returns an EmptyQuerySet -- a QuerySet that always evaluates to an empty list. This can be used in cases where you know that you should return an empty result set and your caller is expecting a QuerySet object (instead of returning an empty list - fo
Abstract base class
using(alias)
exact
none()
44. 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
when you add new apps to INSTALLED_APPS
filter
distinct()
class type
45. A Python "magic method" that returns a unicode "representation" of any object.
ForeignKey
in_bulk(id_list)
Abstract base class
__unicode__()
46. 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
OneToOneField
update(**kwargs)
Proxy model
QuerySet
47. 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
create(**kwargs)
iteration
update(**kwargs)
istartswith
48. 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.
gt
pickling
contains
clear() method
49. Defines a many-to-many relationship. You use it just like any other Field type: by including it as a class attribute of your model.
exists()
delete()
ManyToManyField
latest(field_name=None)
50. Lookup type that returns results less than a given value.
year
search
Many-to-many relationship through an intermediate model
lt