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 for date/datetime fields that finds an exact year match. Takes a four-digit year.
update()
values_list(*fields)
iexact
year
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.
Restrictions on field names
dates(field - kind - order='ASC')
ManyToManyField
Field lookups
3. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exists()
exclude(**kwargs)
primary_key
add()
4. 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
5. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
update(**kwargs)
Q()
month
related_name
6. Lookup type that tests for inclusion in a case-sensitive fashion.
iregex
contains
filter(**kwargs)
istartswith
7. 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
8. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
year
isnull
Model metadata
day
9. Can be used to remove all many-to-many relationships for an instance
reverse()
one-to-one relationship
defer(*fields)
clear() method
10. Fields are specified by these
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
class attributes
update(**kwargs)
11. Lookup type for date/datetime fields that finds an exact day match.
isnull
class attributes
year
day
12. 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()
pk
iterator()
annotate(args - *kwargs)
13. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
iterator()
|
==
model
14. Keyword shortcut for looking up an object by primary key.
pk
reverse name
in_bulk(id_list)
OneToOneField
15. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
get_or_create(**kwargs)
values(*fields)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
in
16. Negation operator for Q objects.
clear() method
~
none()
day
17. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Model metadata
startswith
distinct()
gt
18. 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.
choices
Manager
month
OneToOneField
19. This method immediately deletes the object and has no return value.
in
ForeignKey
delete()
add()
20. 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.
ManyToManyField
blank
regex
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
21. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
filter chaining
istartswith
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
22. 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.
help_text
exact
in
id field
23. 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)
reverse()
Entry.objects.filter(pub_date__year=2005).delete()
==
24. 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
Many-to-many relationship to self
year
range
relationship spanning
25. 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)
Entry.objects.filter(id__gt=4)
Model metadata
count()
primary_key
26. Returns the object matching the given lookup parameters
Many-to-many relationship to self
get(**kwargs)
reverse()
class attributes
27. 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.
ForeignKey
month
F()
filter chaining
28. Lookup type that finds a case-insensitive regular expression match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
in_bulk(id_list)
iregex
many-to-many relationship
29. 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
aggregate(args - *kwargs)
Abstract base class
get(**kwargs)
intermediate models
30. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
get(**kwargs)
Multi-table inheritance
count()
31. 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.
get(**kwargs)
when you add new apps to INSTALLED_APPS
lte
Manager methods
32. This method returns tuples of values when iterated over. Each tuple contains the value from the respective field passed into the call to this method -- so the first item is the first field - etc.
isnull
reverse()
get_or_create(**kwargs)
values_list(*fields)
33. 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
dates(field - kind - order='ASC')
Field lookups
range
34. 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
isnull
slicing
Field lookups
35. 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
F()
related_name
iteration
id field
36. 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
startswith
Restrictions on field names
Abstract base class
37. 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
endswith
when you add new apps to INSTALLED_APPS
annotate(args - *kwargs)
choices
38. 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
Custom model methods
none()
order_by(*fields)
save()
39. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
filter(**kwargs)
ManyToManyField
count()
default
40. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
Entry.objects.filter(pub_date__year=2005).delete()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
pickling
41. a QuerySet can be sliced - using Python's array-slicing syntax.
filter(**kwargs)
slicing
Q(question__istartswith='What')
day
42. This gives your model metadata.
week_day
order_by(*fields)
related_name
Meta class
43. 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.
delete()
==
evaluation
using(alias)
44. 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.
intermediate models
filter chaining
choices tuple
update()
45. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
46. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
clear() method
count()
|
47. 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.
id field
default
related_name
get_absolute_url()
48. This is a criterion that narrow down a QuerySet based on given parameters.
through argument
choices
delete()
filter
49. Conjuntion operator for Q objects.
id field
aggregate(args - *kwargs)
Entry.objects.filter(id__gt=4)
&
50. 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)
Model metadata
in
Manager