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.
filter(**kwargs)
gt
pk
order_by(*fields)
2. 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.
lte
blank
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
order_by(*fields)
3. 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
4. Lookup type that finds a case-sensitive regular expression match.
in
Entry.objects.filter(id__in=[1 - 3 - 4])
class type
regex
5. This method immediately deletes the object and has no return value.
delete()
through argument
null
ForeignKey
6. Lookup type for date/datetime fields that finds an exact day match.
regex
Custom model methods
DoesNotExist
day
7. The default for this is the name of the child class followed by '_set'.
filter
~
reverse()
reverse name
8. Lookup type for date/datetime fields that finds a 'day of the week' match.
add()
week_day
default
when you add new apps to INSTALLED_APPS
9. When to run syncdb
when you add new apps to INSTALLED_APPS
using(alias)
iregex
null
10. 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.
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
choices tuple
Many-to-many relationship through an intermediate model
values_list(*fields)
11. 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()
id field
evaluation
iexact
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
12. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
Entry.objects.filter(id__in=[1 - 3 - 4])
related_name
|
clear() method
13. Lookup type that returns results with a case-insensitive start sequence.
istartswith
iregex
Entry.objects.filter(pub_date__year=2005).delete()
iteration
14. A convenience method for constructing an object and saving it all in one step.
create(**kwargs)
save()
exact
Many-to-many relationship to self
15. This gives your model metadata.
model
Meta class
in_bulk(id_list)
delete()
16. (1) These cannot be Python reserved words - because that would result in a Python syntax error. (2) These cannot contain more than one underscore in a row - due to the way Django's query lookup syntax works.
null
gt
Manager
Restrictions on field names
17. This represents a collection of objects from your database. It can have zero - one or many filters.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
QuerySet
MultipleObjectsReturned
exact
18. Keyword shortcut for looking up an object by primary key.
Q()
Custom model methods
primary_key
pk
19. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
choices tuple
all()
isnull
Field lookups
20. Lookup type that returns results with a case-sensitive start sequence.
update()
iteration
create(**kwargs)
startswith
21. 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.
iexact
Manager methods
when you add new apps to INSTALLED_APPS
ForeignKey
22. 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(**kwargs)
Model metadata
update()
get(**kwargs)
23. 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
24. 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 tuple
gte
relationship spanning
OneToOneField
25. Lookup type that yields a case-insensitive match.
iexact
Q(question__istartswith='What')
endswith
MultipleObjectsReturned
26. 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)
get(**kwargs)
Model metadata
filter(**kwargs)
year
27. Conjuntion operator for Q objects.
save()
Q()
aggregate(args - *kwargs)
&
28. This query finds all entries with an id in the list [1 - 3 - 4]
exact
clear() method
Entry.objects.filter(id__in=[1 - 3 - 4])
Proxy model
29. 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.
lte
all()
get_absolute_url()
F()
30. A Python "magic method" that returns a unicode "representation" of any object.
through argument
__unicode__()
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
F()
31. Returns a new QuerySet containing objects that match the given lookup parameters.
iexact
day
id field
filter(**kwargs)
32. 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
regex
ForeignKey
Custom model methods
33. To activate your models
many-to-one relationship
Q()
get_absolute_url()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
34. 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.
blank
Many-to-many relationship to self
many-to-many relationship
get(**kwargs)
35. 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)
year
ordered
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
36. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
Q(question__istartswith='What')
count()
delete()
distinct()
37. 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.
Entry.objects.filter(pub_date__range=(start_date - end_date))
dates(field - kind - order='ASC')
reverse()
all()
38. a QuerySet can be sliced - using Python's array-slicing syntax.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
pickling
create(**kwargs)
slicing
39. 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
all()
in_bulk(id_list)
get_or_create(**kwargs)
reverse()
40. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
filter(**kwargs)
Field lookups
latest(field_name=None)
values(*fields)
41. Lookup type that tests for inclusion in a case-sensitive fashion.
class attributes
day
week_day
contains
42. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
pk
filter chaining
update(**kwargs)
43. 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
iendswith
startswith
relationship spanning
year
44. This query updates all the headlines with pub_date in 2007 to read 'Everything is the same'.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
45. 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.
filter(**kwargs)
Proxy model
ManyToManyField
get(**kwargs)
46. 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.
related_name
delete()
|
in_bulk(id_list)
47. This field is added automatically - but this behavior can be overridden
ordered
relationship spanning
id field
iteration
48. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
save()
Manager
isnull
49. This query finds all entries with an id greater than 4.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Q()
Entry.objects.filter(id__gt=4)
many-to-one relationship
50. The first element in this iterable is the value that will be stored in the database - the second element will be displayed by the admin interface - or in a ModelChoiceField.
iregex
Proxy model
choices tuple
get_or_create(**kwargs)