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 returns results greater than a given value.
gt
filter(**kwargs)
class attributes
istartswith
2. 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
|
day
exact
3. 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
lte
iregex
select_related()
pickling
4. Manager method used to retrieve every object in a model.
all()
when you add new apps to INSTALLED_APPS
search
db
5. Fields are specified by these
order_by(*fields)
startswith
update(**kwargs)
class attributes
6. Lookup type for date/datetime fields that finds a 'day of the week' match.
lte
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
reverse name
7. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
select_related()
Entry.objects.filter(pub_date__range=(start_date - end_date))
search
8. 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.
9. If this option is True - the field is allowed to be blank. Default is False.
filter chaining
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Manager methods
blank
10. 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.
regex
get(**kwargs)
all()
reverse name
11. 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
clear() method
lte
all()
QuerySet
12. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
delete()
Entry.objects.filter(id__in=[1 - 3 - 4])
exclude(**kwargs)
one-to-one relationship
13. This query finds all entries with an id in the list [1 - 3 - 4]
slicing
ForeignKey
year
Entry.objects.filter(id__in=[1 - 3 - 4])
14. 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.
range
~
id field
pickling
15. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
Multi-table inheritance
defer(*fields)
Meta class
count()
16. When to run syncdb
gte
exact
update(**kwargs)
when you add new apps to INSTALLED_APPS
17. This query deletes all Entry objects with a pub_date year of 2005.
evaluation
Entry.objects.filter(pub_date__year=2005).delete()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
exact
18. 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.
dates(field - kind - order='ASC')
id field
order_by(*fields)
primary_key
19. If this option is True - Django will store empty values as NULL in the database. Default is False.
Custom model methods
Field lookups
null
ForeignKey
20. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
ordered
values_list(*fields)
through argument
21. Lookup type that returns results in a given list.
values_list(*fields)
MultipleObjectsReturned
in
Field lookups
22. Lookup type that returns results greater than or equal to a given value.
create(**kwargs)
help_text
in_bulk(id_list)
gte
23. A Python "magic method" that returns a unicode "representation" of any object.
contains
__unicode__()
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(pub_date__range=(start_date - end_date))
24. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
values(*fields)
none()
istartswith
many-to-one relationship
25. 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
help_text
Proxy model
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
update()
26. Lookup type that yields a case-insensitive match.
unique
lt
iexact
istartswith
27. 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
many-to-many relationship
isnull
delete()
28. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
endswith
isnull
save()
blank
29. Lookup type that finds a case-insensitive regular expression match.
&
iregex
aggregate(args - *kwargs)
iteration
30. Lookup type that returns results less than a given value.
startswith
lt
null
iterator()
31. Lookup type that returns results with a case-insensitive end sequence.
dates(field - kind - order='ASC')
iendswith
lte
filter(**kwargs)
32. The default for this is the name of the child class followed by '_set'.
reverse name
week_day
relationship spanning
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
33. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
Meta class
QuerySet
get_or_create(**kwargs)
34. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Restrictions on field names
contains
lt
get_or_create(**kwargs)
35. Lookup type that returns results that fall into an inclusive date range.
range
get_absolute_url()
aggregate(args - *kwargs)
Proxy model
36. Negation operator for Q objects.
~
filter
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
filter(**kwargs)
37. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
choices
using(alias)
dates(field - kind - order='ASC')
filter(**kwargs)
38. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
__unicode__()
Restrictions on field names
filter chaining
39. Conjuntion operator for Q objects.
defer(*fields)
using(alias)
&
gte
40. 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
class type
order_by(*fields)
F()
filter(**kwargs)
41. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
OneToOneField
==
blank
42. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
distinct()
model
regex
Entry.objects.filter(id__gt=4)
43. This model method saves a model instance to the database. This method has no return value.
save()
clear() method
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
update()
44. 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
null
dates(field - kind - order='ASC')
only(*fields)
unique
45. 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.
reverse name
isnull
values_list(*fields)
iteration
46. These methods are intended to do "table-wide" things.
filter(**kwargs)
add()
~
Manager methods
47. This method immediately deletes the object and has no return value.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
delete()
endswith
iendswith
48. If True - the table does not permit duplicate values for this field.
unique
filter
iendswith
model
49. 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.
create(**kwargs)
model
using(alias)
annotate(args - *kwargs)
50. 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.
iterator()
MultipleObjectsReturned
many-to-one relationship
in_bulk(id_list)