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.
filter(**kwargs)
primary_key
endswith
Custom model methods
2. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
search
pickling
3. To activate your models
Meta class
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exact
~
4. Fields are specified by these
class attributes
pk
QuerySet
in
5. Can be used to remove all many-to-many relationships for an instance
pickling
get_absolute_url()
annotate(args - *kwargs)
clear() method
6. Manager method used to retrieve every object in a model.
exact
annotate(args - *kwargs)
all()
through argument
7. Lookup type that returns results with a case-insensitive end sequence.
Model metadata
iendswith
range
Field lookups
8. 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
9. This is a criterion that narrow down a QuerySet based on given parameters.
Abstract base class
through argument
filter
class attributes
10. 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
get(**kwargs)
select_related()
values(*fields)
unique
11. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
isnull
Restrictions on field names
year
iendswith
12. 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.
exclude(**kwargs)
startswith
delete()
Model metadata
13. 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()
select_related()
endswith
evaluation
Field lookups
14. 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
pk
year
intermediate models
only(*fields)
15. This method immediately deletes the object and has no return value.
pickling
delete()
==
create(**kwargs)
16. Lookup type that finds a case-sensitive regular expression match.
choices tuple
F()
values(*fields)
regex
17. The value given in the absence of a specified value for the field. This can be a value or a callable object. If callable it will be called every time a new object is created.
DoesNotExist
range
slicing
default
18. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
choices
reverse()
get(**kwargs)
count()
19. This query finds all entries with an id in the list [1 - 3 - 4]
choices tuple
update(**kwargs)
Proxy model
Entry.objects.filter(id__in=[1 - 3 - 4])
20. These add custom "row-level" functionality to your objects. These act on a particular model instance.
exists()
Restrictions on field names
Custom model methods
only(*fields)
21. This field is added automatically - but this behavior can be overridden
iteration
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
id field
Proxy model
22. 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.
OneToOneField
all()
istartswith
get(**kwargs)
23. 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
all()
update(**kwargs)
distinct()
gt
24. Lookup type that returns results greater than a given value.
many-to-many relationship
gt
lte
Entry.objects.filter(pub_date__year=2005).delete()
25. 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
update(**kwargs)
Multi-table inheritance
latest(field_name=None)
none()
26. Used to get a QuerySet for a model. This is called 'objects' by default.
reverse()
when you add new apps to INSTALLED_APPS
exact
Manager
27. If this option is True - the field is allowed to be blank. Default is False.
save()
blank
count()
year
28. 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
Entry.objects.filter(pub_date__year=2005).delete()
Custom model methods
blank
annotate(args - *kwargs)
29. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iteration
class type
distinct()
many-to-many relationship
30. Lookup type that yields a case-insensitive match.
dates(field - kind - order='ASC')
when you add new apps to INSTALLED_APPS
week_day
iexact
31. 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.
relationship spanning
QuerySet
delete()
aggregate(args - *kwargs)
32. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
Entry.objects.filter(id__gt=4)
choices tuple
class type
isnull
33. 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.
==
endswith
related_name
order_by(*fields)
34. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
one-to-one relationship
slicing
model
choices
35. The default for this is the name of the child class followed by '_set'.
istartswith
reverse name
search
in_bulk(id_list)
36. 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
Many-to-many relationship through an intermediate model
class type
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
defer(*fields)
37. 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.
==
Manager methods
MultipleObjectsReturned
OneToOneField
38. Lookup type that returns results that fall into an inclusive date range.
range
Custom model methods
none()
delete()
39. 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.
pickling
lte
unique
related_name
40. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
Restrictions on field names
iexact
regex
41. 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.
delete()
choices
&
get_absolute_url()
42. These methods are intended to do "table-wide" things.
latest(field_name=None)
Manager methods
create(**kwargs)
contains
43. Returns a DateQuerySet -- a QuerySet that evaluates to a list of datetime.datetime objects representing all available dates of a particular kind within the contents of the QuerySet.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
44. a QuerySet can be sliced - using Python's array-slicing syntax.
unique
search
slicing
using(alias)
45. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
relationship spanning
contains
distinct()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
46. 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.
==
relationship spanning
filter
Q()
47. 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.
Meta class
db
Many-to-many relationship to self
evaluation
48. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
exclude(**kwargs)
Proxy model
iendswith
49. 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.
select_related()
Multi-table inheritance
regex
Restrictions on field names
50. Exception raised by get(**kwargs) if more than one item matches the query.
lte
Manager
when you add new apps to INSTALLED_APPS
MultipleObjectsReturned