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. When to run syncdb
when you add new apps to INSTALLED_APPS
Model metadata
==
Meta class
2. The default for this is the name of the child class followed by '_set'.
gt
count()
reverse name
save()
3. 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.
filter(**kwargs)
F()
week_day
get(**kwargs)
4. 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
regex
through argument
iendswith
Abstract base class
5. Conjuntion operator for Q objects.
&
null
MultipleObjectsReturned
iterator()
6. Lookup type that yields an "exact" match. If you don't provide a lookup type -- that is - if your keyword argument doesn't contain a double underscore -- the lookup type is assumed to be of this sort.
all()
exact
pickling
all()
7. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
relationship spanning
iteration
order_by(*fields)
db
8. 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
MultipleObjectsReturned
many-to-many relationship
endswith
defer(*fields)
9. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
~
istartswith
Entry.objects.filter(id__in=[1 - 3 - 4])
10. 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
search
null
all()
distinct()
11. Used to get a QuerySet for a model. This is called 'objects' by default.
one-to-one relationship
Manager
ManyToManyField
none()
12. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.
when you add new apps to INSTALLED_APPS
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
OneToOneField
13. Lookup type that returns results less than a given value.
lt
isnull
|
OneToOneField
14. Lookup type that finds a case-sensitive regular expression match.
none()
regex
dates(field - kind - order='ASC')
iendswith
15. This field is added automatically - but this behavior can be overridden
==
Custom model methods
id field
create(**kwargs)
16. If this option is True - Django will store empty values as NULL in the database. Default is False.
null
lt
Field lookups
__unicode__()
17. 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.
save()
many-to-one relationship
default
day
18. If True - the table does not permit duplicate values for this field.
ForeignKey
dates(field - kind - order='ASC')
pk
unique
19. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
pk
ordered
Model metadata
delete()
20. 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_absolute_url()
regex
through argument
in_bulk(id_list)
21. This method immediately deletes the object and has no return value.
class type
delete()
all()
gte
22. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
DoesNotExist
add()
startswith
23. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
related_name
iendswith
iregex
gt
24. 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.
in_bulk(id_list)
iterator()
reverse name
slicing
25. Lookup type that tests for inclusion in a case-sensitive fashion.
help_text
contains
values(*fields)
gte
26. 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.
reverse name
default
search
all()
27. 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
class type
select_related()
filter chaining
through argument
28. Lookup type that returns results with a case-sensitive start sequence.
primary_key
startswith
clear() method
range
29. 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.
ForeignKey
iterator()
endswith
|
30. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
default
==
get(**kwargs)
31. 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
32. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
values_list(*fields)
Manager methods
year
ordered
33. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
startswith
values(*fields)
select_related()
search
34. Lookup type that yields a case-insensitive match.
iexact
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
relationship spanning
search
35. 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
slicing
aggregate(args - *kwargs)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
F()
36. Lookup type for date/datetime fields that finds an exact day match.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
null
day
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
37. 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.
filter chaining
Manager
null
evaluation
38. Returns a dictionary of aggregate values (averages - sums - etc) calculated over the QuerySet. Each argument to this method specifies a value that will be included in the dictionary that is returned.
aggregate(args - *kwargs)
gte
choices tuple
Multi-table inheritance
39. This query deletes all Entry objects with a pub_date year of 2005.
values_list(*fields)
filter(**kwargs)
MultipleObjectsReturned
Entry.objects.filter(pub_date__year=2005).delete()
40. Lookup type that returns results less than or equal to a given value.
lte
latest(field_name=None)
contains
defer(*fields)
41. 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.
intermediate models
Many-to-many relationship through an intermediate model
evaluation
help_text
42. 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.
Custom model methods
choices
all()
year
43. This model method is used for updating a ManyToManyField.
Manager methods
all()
add()
Many-to-many relationship through an intermediate model
44. Lookup type that returns results greater than or equal to a given value.
gte
ManyToManyField
unique
choices tuple
45. Lookup type that returns results that fall into an inclusive date range.
range
through argument
filter(**kwargs)
Q(question__istartswith='What')
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.
isnull
pickling
db
Custom model methods
47. 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.
relationship spanning
MultipleObjectsReturned
slicing
order_by(*fields)
48. This represents a collection of objects from your database. It can have zero - one or many filters.
create(**kwargs)
QuerySet
many-to-one relationship
istartswith
49. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
id field
ordered
get_or_create(**kwargs)
Abstract base class
50. 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
day
Entry.objects.filter(id__in=[1 - 3 - 4])
iterator()
F()