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. 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.
Model metadata
get_absolute_url()
reverse()
range
2. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
choices tuple
==
day
class attributes
3. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
iterator()
iexact
regex
4. This query finds all entries with an id greater than 4.
iteration
Entry.objects.filter(id__gt=4)
month
startswith
5. Returns the most recent object in the table - by date - using the field_name provided as the date field.
get_absolute_url()
exact
Many-to-many relationship to self
latest(field_name=None)
6. These add custom "row-level" functionality to your objects. These act on a particular model instance.
endswith
month
Custom model methods
Entry.objects.filter(pub_date__range=(start_date - end_date))
7. Can be used to remove all many-to-many relationships for an instance
iregex
get_absolute_url()
&
clear() method
8. Manager method used to retrieve every object in a model.
filter
Manager methods
class attributes
all()
9. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
many-to-many relationship
Many-to-many relationship to self
endswith
10. This method immediately deletes the object and has no return value.
pickling
filter
select_related()
delete()
11. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
contains
none()
Q(question__istartswith='What')
12. If this option is True - the field is allowed to be blank. Default is False.
Q()
MultipleObjectsReturned
blank
QuerySet
13. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
ordered
get(**kwargs)
defer(*fields)
search
14. 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
pickling
aggregate(args - *kwargs)
iterator()
annotate(args - *kwargs)
15. This is a criterion that narrow down a QuerySet based on given parameters.
order_by(*fields)
isnull
filter
MultipleObjectsReturned
16. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
count()
default
exclude(**kwargs)
17. 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
search
class type
related_name
using(alias)
18. 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
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
pickling
only(*fields)
19. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
one-to-one relationship
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
values(*fields)
endswith
20. A Python "magic method" that returns a unicode "representation" of any object.
Manager methods
__unicode__()
Entry.objects.filter(id__in=[1 - 3 - 4])
evaluation
21. 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
Abstract base class
Many-to-many relationship to self
values(*fields)
annotate(args - *kwargs)
22. 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()
choices tuple
evaluation
gt
using(alias)
23. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
Proxy model
lte
blank
24. 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
Manager methods
filter(**kwargs)
year
25. 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.
choices
relationship spanning
OneToOneField
Restrictions on field names
26. Conjuntion operator for Q objects.
slicing
distinct()
&
pk
27. Lookup type that returns results in a given list.
primary_key
values_list(*fields)
update(**kwargs)
in
28. 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
month
F()
annotate(args - *kwargs)
Proxy model
29. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
help_text
Manager
==
isnull
30. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
help_text
Field lookups
filter chaining
Many-to-many relationship through an intermediate model
31. Used to get a QuerySet for a model. This is called 'objects' by default.
OneToOneField
Model metadata
Manager
aggregate(args - *kwargs)
32. Exception raised by get(**kwargs) if no items match the query.
|
class attributes
DoesNotExist
blank
33. Lookup type for date/datetime fields that finds an exact day match.
day
iteration
Entry.objects.filter(id__gt=4)
default
34. The database that will be used if this query is executed now
filter(**kwargs)
gt
Manager
db
35. If True - this field is the primary key for the model.
all()
pickling
iexact
primary_key
36. This query deletes all Entry objects with a pub_date year of 2005.
range
F()
get(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
37. Keyword shortcut for looking up an object by primary key.
add()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
pk
in_bulk(id_list)
38. Lookup type that finds a case-sensitive regular expression match.
exclude(**kwargs)
choices tuple
pickling
regex
39. Lookup type that finds a case-insensitive regular expression match.
F()
defer(*fields)
filter
iregex
40. 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.
update()
MultipleObjectsReturned
dates(field - kind - order='ASC')
when you add new apps to INSTALLED_APPS
41. 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
range
in
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
all()
42. 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
43. 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
ForeignKey
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
select_related()
choices tuple
44. A convenience method for constructing an object and saving it all in one step.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
create(**kwargs)
filter chaining
pk
45. This model method saves a model instance to the database. This method has no return value.
create(**kwargs)
save()
Manager
choices tuple
46. Lookup type that yields a case-insensitive match.
get_or_create(**kwargs)
iexact
Many-to-many relationship through an intermediate model
Manager
47. Exception raised by get(**kwargs) if more than one item matches the query.
Entry.objects.filter(id__in=[1 - 3 - 4])
Entry.objects.filter(pub_date__year=2005).delete()
MultipleObjectsReturned
id field
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.
search
Model metadata
reverse name
aggregate(args - *kwargs)
49. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
many-to-many relationship
values(*fields)
filter(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
50. This query finds all entries with an id in the list [1 - 3 - 4]
MultipleObjectsReturned
Many-to-many relationship to self
delete()
Entry.objects.filter(id__in=[1 - 3 - 4])