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. a QuerySet can be sliced - using Python's array-slicing syntax.
filter(**kwargs)
slicing
ForeignKey
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
2. (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.
filter chaining
select_related()
Restrictions on field names
in_bulk(id_list)
3. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
Restrictions on field names
exists()
evaluation
4. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
Many-to-many relationship to self
pk
range
==
5. Keyword shortcut for looking up an object by primary key.
startswith
pk
distinct()
dates(field - kind - order='ASC')
6. This query deletes all Entry objects with a pub_date year of 2005.
distinct()
Manager
Q()
Entry.objects.filter(pub_date__year=2005).delete()
7. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
month
class attributes
pickling
count()
8. Lookup type that tests for inclusion in a case-sensitive fashion.
&
contains
Proxy model
pickling
9. Lookup type that finds a case-sensitive regular expression match.
dates(field - kind - order='ASC')
defer(*fields)
regex
endswith
10. Lookup type for date/datetime fields that finds an exact day match.
day
using(alias)
get_or_create(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
11. 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
iregex
iexact
&
select_related()
12. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
iterator()
startswith
DoesNotExist
13. Lookup type that returns results in a given list.
gt
all()
in
many-to-many relationship
14. 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
15. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iteration
none()
many-to-many relationship
startswith
16. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
many-to-many relationship
null
exists()
17. Lookup type that returns results that fall into an inclusive date range.
filter
in_bulk(id_list)
iexact
range
18. 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)
month
all()
Restrictions on field names
19. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
delete()
get(**kwargs)
clear() method
20. 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
slicing
save()
order_by(*fields)
defer(*fields)
21. A Q object that asks for entries with a question value that start with 'Who' or do not have a publication date of 2005.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
22. If True - the table does not permit duplicate values for this field.
unique
distinct()
Restrictions on field names
help_text
23. Lookup type that returns results less than or equal to a given value.
lte
month
Restrictions on field names
QuerySet
24. Returns a new QuerySet containing objects that match the given lookup parameters.
pk
get_or_create(**kwargs)
filter(**kwargs)
defer(*fields)
25. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
filter
class attributes
Model metadata
26. This represents a collection of objects from your database. It can have zero - one or many filters.
__unicode__()
QuerySet
iendswith
choices
27. Lookup type that finds a case-insensitive regular expression match.
order_by(*fields)
iregex
delete()
OneToOneField
28. 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.
update()
__unicode__()
ForeignKey
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
29. 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
gt
values_list(*fields)
Abstract base class
many-to-many relationship
30. 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.
default
Q()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Entry.objects.filter(id__gt=4)
31. 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
32. 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.
count()
lte
==
Multi-table inheritance
33. 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
relationship spanning
db
exact
only(*fields)
34. 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
using(alias)
Manager
Field lookups
F()
35. 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.
help_text
pickling
Many-to-many relationship through an intermediate model
filter chaining
36. Lookup type that returns results with a case-sensitive end sequence.
blank
ManyToManyField
get_or_create(**kwargs)
endswith
37. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
null
range
QuerySet
month
38. 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)
unique
get(**kwargs)
Model metadata
Many-to-many relationship through an intermediate model
39. 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.
id field
contains
delete()
help_text
40. 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
Custom model methods
gte
model
update(**kwargs)
41. The database that will be used if this query is executed now
regex
db
filter(**kwargs)
clear() method
42. 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.
clear() method
pickling
get_absolute_url()
MultipleObjectsReturned
43. 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.
get_or_create(**kwargs)
none()
many-to-one relationship
Entry.objects.filter(pub_date__range=(start_date - end_date))
44. A Python "magic method" that returns a unicode "representation" of any object.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
__unicode__()
contains
primary_key
45. These methods are intended to do "table-wide" things.
exclude(**kwargs)
Proxy model
Many-to-many relationship to self
Manager methods
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.
get_absolute_url()
Many-to-many relationship through an intermediate model
Q()
endswith
47. 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.
lt
get(**kwargs)
get_or_create(**kwargs)
isnull
48. 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
through argument
search
Entry.objects.filter(id__in=[1 - 3 - 4])
49. 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
delete()
none()
id field
Restrictions on field names
50. 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