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. These methods are intended to do "table-wide" things.
exclude(**kwargs)
Manager methods
|
isnull
2. Lookup type that returns results with a case-insensitive start sequence.
Manager
contains
MultipleObjectsReturned
istartswith
3. This query finds all entries with an id greater than 4.
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)
null
iendswith
4. 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
5. 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.
Model metadata
count()
Q()
default
6. Can be used to remove all many-to-many relationships for an instance
iendswith
clear() method
isnull
Many-to-many relationship through an intermediate model
7. a QuerySet can be sliced - using Python's array-slicing syntax.
default
iterator()
slicing
lte
8. 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
day
iendswith
none()
Manager methods
9. 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
reverse()
Proxy model
evaluation
OneToOneField
10. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
aggregate(args - *kwargs)
values_list(*fields)
get_absolute_url()
11. 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
dates(field - kind - order='ASC')
only(*fields)
get_absolute_url()
12. To activate your models
QuerySet
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
default
Proxy model
13. 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
intermediate models
iterator()
filter chaining
14. Lookup type that yields a case-insensitive match.
iexact
filter(**kwargs)
filter chaining
regex
15. If True - the table does not permit duplicate values for this field.
many-to-one relationship
save()
none()
unique
16. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
gte
help_text
OneToOneField
17. This model method saves a model instance to the database. This method has no return value.
annotate(args - *kwargs)
Proxy model
save()
iteration
18. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
dates(field - kind - order='ASC')
get_absolute_url()
19. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
ManyToManyField
in_bulk(id_list)
none()
one-to-one relationship
20. The default for this is the name of the child class followed by '_set'.
__unicode__()
intermediate models
reverse name
defer(*fields)
21. 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.
update(**kwargs)
aggregate(args - *kwargs)
lt
get(**kwargs)
22. 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
reverse name
select_related()
Restrictions on field names
month
23. This query finds all entries between a start date of start_date and an end date of end_date.
Proxy model
ForeignKey
Entry.objects.filter(id__in=[1 - 3 - 4])
Entry.objects.filter(pub_date__range=(start_date - end_date))
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.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
25. 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.
order_by(*fields)
update()
evaluation
help_text
26. This query deletes all Entry objects with a pub_date year of 2005.
QuerySet
none()
startswith
Entry.objects.filter(pub_date__year=2005).delete()
27. 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.
slicing
ManyToManyField
order_by(*fields)
get(**kwargs)
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
gt
choices tuple
add()
29. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
none()
values_list(*fields)
related_name
regex
30. 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
Multi-table inheritance
defer(*fields)
exact
update(**kwargs)
31. 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
32. This model method is used for updating a ManyToManyField.
add()
default
primary_key
none()
33. Lookup type that returns results greater than or equal to a given value.
gte
in_bulk(id_list)
only(*fields)
values(*fields)
34. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
help_text
defer(*fields)
pk
35. This method immediately deletes the object and has no return value.
delete()
default
intermediate models
in
36. (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.
when you add new apps to INSTALLED_APPS
db
Restrictions on field names
Entry.objects.filter(id__in=[1 - 3 - 4])
37. This query finds all entries with an id in the list [1 - 3 - 4]
relationship spanning
through argument
intermediate models
Entry.objects.filter(id__in=[1 - 3 - 4])
38. 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
through argument
contains
exists()
Entry.objects.filter(id__in=[1 - 3 - 4])
39. 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.
create(**kwargs)
all()
choices tuple
defer(*fields)
40. 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
get_absolute_url()
class type
Entry.objects.filter(id__in=[1 - 3 - 4])
default
41. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
get(**kwargs)
values_list(*fields)
many-to-many relationship
exclude(**kwargs)
42. 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_or_create(**kwargs)
get_absolute_url()
iexact
in
43. 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.
Proxy model
iregex
pickling
Entry.objects.filter(pub_date__range=(start_date - end_date))
44. Negation operator for Q objects.
id field
~
iendswith
Q(question__istartswith='What')
45. 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
DoesNotExist
reverse name
pickling
Abstract base class
46. This gives your model metadata.
get(**kwargs)
&
when you add new apps to INSTALLED_APPS
Meta class
47. 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.
reverse name
get(**kwargs)
gte
Many-to-many relationship through an intermediate model
48. 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
using(alias)
create(**kwargs)
MultipleObjectsReturned
49. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
reverse name
reverse()
istartswith
50. Lookup type that returns results with a case-sensitive start sequence.
isnull
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
Many-to-many relationship to self
startswith