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 tests for inclusion in a case-sensitive fashion.
contains
reverse()
get(**kwargs)
isnull
2. 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.
Multi-table inheritance
count()
Abstract base class
gt
3. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
Custom model methods
gte
filter chaining
4. Lookup type for date/datetime fields that finds an exact day match.
day
get_or_create(**kwargs)
select_related()
iterator()
5. If this option is True - the field is allowed to be blank. Default is False.
blank
evaluation
iterator()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
6. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
month
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
endswith
filter(**kwargs)
7. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
Meta class
year
exists()
Q()
8. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
help_text
latest(field_name=None)
related_name
9. Lookup type for date/datetime fields that finds a 'day of the week' match.
distinct()
pickling
week_day
exclude(**kwargs)
10. 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.
in
annotate(args - *kwargs)
all()
OneToOneField
11. 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
choices tuple
Many-to-many relationship to self
aggregate(args - *kwargs)
relationship spanning
12. 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.
Many-to-many relationship through an intermediate model
update()
filter(**kwargs)
iendswith
13. This model method is used for updating a ManyToManyField.
year
Multi-table inheritance
add()
Entry.objects.filter(id__in=[1 - 3 - 4])
14. 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))
istartswith
class attributes
day
15. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
exact
id field
all()
F()
16. 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
iexact
id field
only(*fields)
Multi-table inheritance
17. Lookup type that returns results with a case-insensitive end sequence.
add()
iendswith
create(**kwargs)
day
18. Manager method used to retrieve every object in a model.
year
delete()
day
all()
19. 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
20. This gives your model metadata.
Meta class
get_absolute_url()
order_by(*fields)
ordered
21. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
get_or_create(**kwargs)
isnull
many-to-many relationship
evaluation
22. Lookup type that finds a case-insensitive regular expression match.
iregex
QuerySet
in_bulk(id_list)
Many-to-many relationship through an intermediate model
23. Returns the object matching the given lookup parameters
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
get(**kwargs)
range
delete()
24. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
class attributes
when you add new apps to INSTALLED_APPS
update()
25. 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.
latest(field_name=None)
values_list(*fields)
iexact
week_day
26. 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
filter
iregex
Meta class
Proxy model
27. This method immediately deletes the object and has no return value.
delete()
ForeignKey
in_bulk(id_list)
pickling
28. 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
iregex
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
==
29. Specifies the model that will be used to govern the many-to-many relationship. You can then put extra fields on the intermediate model. The intermediate model is associated with the ManyToManyField using this to point to the model that will act as an
OneToOneField
dates(field - kind - order='ASC')
get_or_create(**kwargs)
through argument
30. The database that will be used if this query is executed now
db
Restrictions on field names
through argument
related_name
31. The default for this is the name of the child class followed by '_set'.
null
all()
delete()
reverse name
32. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
==
defer(*fields)
iregex
33. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
only(*fields)
iendswith
exact
34. This query finds all entries with an id greater than 4.
exclude(**kwargs)
help_text
QuerySet
Entry.objects.filter(id__gt=4)
35. 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.
Many-to-many relationship through an intermediate model
choices
when you add new apps to INSTALLED_APPS
dates(field - kind - order='ASC')
36. Lookup type that finds a case-sensitive regular expression match.
defer(*fields)
when you add new apps to INSTALLED_APPS
exists()
regex
37. 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.
through argument
Manager methods
reverse()
latest(field_name=None)
38. If True - this field is the primary key for the model.
week_day
primary_key
through argument
latest(field_name=None)
39. 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.
help_text
~
ForeignKey
many-to-many relationship
40. Fields are specified by these
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
select_related()
exclude(**kwargs)
class attributes
41. 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
42. 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.
filter chaining
Abstract base class
unique
many-to-one relationship
43. 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
primary_key
Field lookups
class attributes
update(**kwargs)
44. 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.
Model metadata
reverse()
choices tuple
endswith
45. Lookup type that returns results with a case-insensitive start sequence.
week_day
istartswith
gt
endswith
46. 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.
filter(**kwargs)
pickling
clear() method
all()
47. Lookup type that returns results with a case-sensitive start sequence.
values(*fields)
Q(question__istartswith='What')
delete()
startswith
48. To activate your models
MultipleObjectsReturned
iteration
istartswith
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
49. These methods are intended to do "table-wide" things.
Manager
Manager methods
delete()
contains
50. 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
annotate(args - *kwargs)
in_bulk(id_list)
all()
filter