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. 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.
__unicode__()
count()
values_list(*fields)
reverse name
2. A convenience method for looking up an object with the given kwargs - creating one if necessary.
Meta class
one-to-one relationship
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.
3. Manager method used to retrieve every object in a model.
exact
reverse name
Custom model methods
all()
4. 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.
using(alias)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
get_or_create(**kwargs)
Proxy model
5. 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
Proxy model
Abstract base class
Meta class
reverse()
6. To activate your models
QuerySet
range
day
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
7. Lookup type that returns results in a given list.
&
select_related()
in
contains
8. This is a criterion that narrow down a QuerySet based on given parameters.
Model metadata
search
filter
help_text
9. 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
10. Lookup type that returns results greater than or equal to a given value.
iendswith
choices tuple
gte
Many-to-many relationship through an intermediate model
11. This gives your model metadata.
Custom model methods
distinct()
Meta class
Entry.objects.filter(pub_date__range=(start_date - end_date))
12. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
ForeignKey
Abstract base class
get(**kwargs)
13. Lookup type that returns results with a case-sensitive start sequence.
startswith
latest(field_name=None)
blank
reverse name
14. 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.
startswith
get(**kwargs)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
db
15. Lookup type that returns results that fall into an inclusive date range.
startswith
Multi-table inheritance
range
create(**kwargs)
16. Lookup type for date/datetime fields that finds a 'day of the week' match.
ForeignKey
filter
delete()
week_day
17. 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.
only(*fields)
__unicode__()
|
get_absolute_url()
18. This field is added automatically - but this behavior can be overridden
id field
through argument
get_or_create(**kwargs)
class attributes
19. 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
values(*fields)
filter chaining
pk
20. 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.
dates(field - kind - order='ASC')
filter
through argument
pickling
21. If True - this field is the primary key for the model.
filter(**kwargs)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
dates(field - kind - order='ASC')
primary_key
22. 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()
lt
regex
Q(question__istartswith='What')
23. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
intermediate models
==
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
24. 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
when you add new apps to INSTALLED_APPS
class attributes
order_by(*fields)
Proxy model
25. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Restrictions on field names
month
distinct()
update(**kwargs)
26. 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
get_absolute_url()
week_day
only(*fields)
class attributes
27. Used to get a QuerySet for a model. This is called 'objects' by default.
Manager
iregex
class attributes
values(*fields)
28. 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()
Meta class
evaluation
lte
OneToOneField
29. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
default
Entry.objects.filter(id__in=[1 - 3 - 4])
distinct()
iteration
30. This method immediately deletes the object and has no return value.
related_name
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
delete()
one-to-one relationship
31. 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.
class type
reverse()
id field
gte
32. Lookup type that finds a case-sensitive regular expression match.
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
reverse()
regex
related_name
33. 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
aggregate(args - *kwargs)
relationship spanning
class type
dates(field - kind - order='ASC')
34. 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.
Manager
update()
class type
class attributes
35. 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.
startswith
exact
distinct()
Entry.objects.filter(pub_date__year=2005).delete()
36. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
iexact
class type
evaluation
37. Lookup type that yields a case-insensitive match.
values_list(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
exact
iexact
38. 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
update()
isnull
F()
regex
39. 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
count()
values(*fields)
save()
40. Lookup type for date/datetime fields that finds an exact day match.
update()
isnull
day
Abstract base class
41. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
range
Many-to-many relationship to self
values(*fields)
search
42. The default for this is the name of the child class followed by '_set'.
reverse name
istartswith
default
all()
43. Keyword shortcut for looking up an object by primary key.
update()
distinct()
Manager
pk
44. 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
filter
model
relationship spanning
filter chaining
45. 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.
month
help_text
get_or_create(**kwargs)
class attributes
46. 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.
order_by(*fields)
OneToOneField
through argument
choices
47. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
pickling
ForeignKey
Field lookups
Model metadata
48. This query finds all entries between a start date of start_date and an end date of end_date.
related_name
lte
Entry.objects.filter(pub_date__range=(start_date - end_date))
delete()
49. 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.
lt
filter
Many-to-many relationship to self
Entry.objects.filter(id__gt=4)
50. restrictions on ________: (1) Your intermediate model must contain one - and only one - foreign key to the target model. (2) Your intermediate model must contain one - and only one - foreign key to the source model. (3) When defining a many-to-many r
&
intermediate models
Meta class
null