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. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
ForeignKey
istartswith
annotate(args - *kwargs)
count()
2. 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.
get(**kwargs)
iterator()
range
default
3. A convenience method for constructing an object and saving it all in one step.
null
create(**kwargs)
|
order_by(*fields)
4. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
Proxy model
class attributes
ordered
5. Lookup type that returns results with a case-sensitive start sequence.
regex
startswith
exclude(**kwargs)
gt
6. 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.
save()
none()
search
exact
7. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
class attributes
default
Q(question__istartswith='What')
8. 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.
istartswith
filter chaining
Manager
many-to-one relationship
9. 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
filter chaining
all()
filter(**kwargs)
distinct()
10. 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.
regex
ManyToManyField
unique
Entry.objects.filter(pub_date__year=2005).delete()
11. Exception raised by get(**kwargs) if no items match the query.
choices tuple
==
ForeignKey
DoesNotExist
12. 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)
__unicode__()
null
Model metadata
get(**kwargs)
13. Can be used to remove all many-to-many relationships for an instance
clear() method
add()
many-to-one relationship
in_bulk(id_list)
14. Used to get a QuerySet for a model. This is called 'objects' by default.
relationship spanning
Field lookups
in
Manager
15. This is a criterion that narrow down a QuerySet based on given parameters.
filter
intermediate models
class type
order_by(*fields)
16. Lookup type that returns results greater than a given value.
filter
gt
update(**kwargs)
many-to-many relationship
17. Returns a new QuerySet containing objects that match the given lookup parameters.
intermediate models
Abstract base class
Q(question__istartswith='What')
filter(**kwargs)
18. 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.
primary_key
DoesNotExist
reverse()
select_related()
19. Lookup type that returns results in a given list.
Proxy model
in
when you add new apps to INSTALLED_APPS
only(*fields)
20. A convenience method for looking up an object with the given kwargs - creating one if necessary.
choices
iregex
get_or_create(**kwargs)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
21. Disjunction operator for Q objects.
|
MultipleObjectsReturned
Meta class
save()
22. This represents a collection of objects from your database. It can have zero - one or many filters.
exclude(**kwargs)
QuerySet
update()
many-to-one relationship
23. Lookup type that returns results less than a given value.
lt
in
one-to-one relationship
filter
24. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
reverse()
Custom model methods
Field lookups
filter(**kwargs)
25. 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
regex
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
add()
26. In some complex data-modeling situations - your models might contain a lot of fields - some of which could contain a lot of data (for example - text fields) - or require expensive processing to convert them to Python objects. If you are using the res
ManyToManyField
Multi-table inheritance
all()
defer(*fields)
27. 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
blank
values_list(*fields)
choices
28. 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.
unique
regex
get(**kwargs)
get_absolute_url()
29. 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))
Proxy model
primary_key
get(**kwargs)
30. Negation operator for Q objects.
~
pickling
create(**kwargs)
select_related()
31. Manager method used to retrieve every object in a model.
all()
using(alias)
defer(*fields)
delete()
32. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
when you add new apps to INSTALLED_APPS
iterator()
day
model
33. 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
34. 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
range
related_name
in
class type
35. 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.
get_or_create(**kwargs)
Proxy model
filter(**kwargs)
values_list(*fields)
36. Fields are specified by these
iteration
in_bulk(id_list)
ManyToManyField
class attributes
37. 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 through an intermediate model
none()
Q(question__istartswith='What')
relationship spanning
38. These methods are intended to do "table-wide" things.
Manager methods
gte
regex
latest(field_name=None)
39. This gives your model metadata.
save()
Meta class
when you add new apps to INSTALLED_APPS
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
40. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
|
isnull
MultipleObjectsReturned
all()
41. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
OneToOneField
blank
iregex
42. 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
none()
all()
ordered
Q()
43. In this case - an intermediate model can have multiple foreign keys to the source model. Here - two foreign keys to the same model are permitted - but they will be treated as the two (different) sides of the many-to-many relation.
Many-to-many relationship to self
slicing
exists()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
44. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
ForeignKey
ManyToManyField
filter chaining
45. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
year
using(alias)
aggregate(args - *kwargs)
46. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
through argument
Q(question__istartswith='What')
Meta class
month
47. This query finds all entries with an id in the list [1 - 3 - 4]
lt
F()
aggregate(args - *kwargs)
Entry.objects.filter(id__in=[1 - 3 - 4])
48. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
pickling
Q(question__istartswith='What')
49. 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.
reverse()
Entry.objects.filter(id__gt=4)
Manager methods
ForeignKey
50. Takes a list of primary-key values and returns a dictionary mapping each primary-key value to an instance of the object with the given ID.
search
all()
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
in_bulk(id_list)