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. a QuerySet can be sliced - using Python's array-slicing syntax.
evaluation
Q()
add()
slicing
2. When to run syncdb
when you add new apps to INSTALLED_APPS
db
reverse()
one-to-one relationship
3. 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.
choices tuple
Manager
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
regex
4. Lookup type that returns results less than a given value.
day
null
class type
lt
5. 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)
latest(field_name=None)
choices
Q(question__istartswith='What')
6. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
exists()
Field lookups
relationship spanning
latest(field_name=None)
7. 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.
exact
QuerySet
db
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
8. 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.
only(*fields)
using(alias)
get(**kwargs)
select_related()
9. This query finds all entries with an id greater than 4.
aggregate(args - *kwargs)
choices tuple
Entry.objects.filter(id__gt=4)
exact
10. Conjuntion operator for Q objects.
iterator()
pk
DoesNotExist
&
11. 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
__unicode__()
MultipleObjectsReturned
defer(*fields)
Abstract base class
12. Returns the object matching the given lookup parameters
exists()
exclude(**kwargs)
through argument
get(**kwargs)
13. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
intermediate models
Proxy model
help_text
model
14. 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.
delete()
using(alias)
__unicode__()
exclude(**kwargs)
15. Exception raised by get(**kwargs) if more than one item matches the query.
|
Meta class
ForeignKey
MultipleObjectsReturned
16. 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
Multi-table inheritance
db
defer(*fields)
all()
17. A convenience method for constructing an object and saving it all in one step.
Manager methods
startswith
create(**kwargs)
lte
18. Keyword shortcut for looking up an object by primary key.
delete()
pk
__unicode__()
exclude(**kwargs)
19. Lookup type that returns results less than or equal to a given value.
iregex
select_related()
lte
null
20. This represents a collection of objects from your database. It can have zero - one or many filters.
QuerySet
choices tuple
week_day
ordered
21. Lookup type that returns results with a case-insensitive start sequence.
in
get(**kwargs)
istartswith
aggregate(args - *kwargs)
22. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
F()
many-to-many relationship
Entry.objects.filter(pub_date__range=(start_date - end_date))
one-to-one relationship
23. This gives your model metadata.
Meta class
Many-to-many relationship to self
all()
create(**kwargs)
24. Lookup type that tests for inclusion in a case-sensitive fashion.
isnull
contains
when you add new apps to INSTALLED_APPS
Field lookups
25. This field is added automatically - but this behavior can be overridden
id field
update()
Abstract base class
filter(**kwargs)
26. This method immediately deletes the object and has no return value.
QuerySet
reverse()
only(*fields)
delete()
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
default
isnull
one-to-one relationship
through argument
28. Lookup type for date/datetime fields that finds an exact day match.
endswith
reverse name
day
Manager
29. 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)
Model metadata
values(*fields)
dates(field - kind - order='ASC')
Meta class
30. Lookup type for date/datetime fields that finds a 'day of the week' match.
search
week_day
id field
delete()
31. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Custom model methods
distinct()
delete()
exclude(**kwargs)
32. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
one-to-one relationship
search
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
distinct()
33. Returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
iregex
pickling
Multi-table inheritance
34. This model method is used for updating a ManyToManyField.
ManyToManyField
year
add()
get(**kwargs)
35. Returns True if the QuerySet contains any results - and False if not. This tries to perform the query in the simplest and fastest way possible - but it does execute nearly the same query. This means that calling this method on a queryset is faster th
&
dates(field - kind - order='ASC')
exists()
iexact
36. 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.
create(**kwargs)
endswith
id field
Many-to-many relationship through an intermediate model
37. Returns the most recent object in the table - by date - using the field_name provided as the date field.
iendswith
latest(field_name=None)
Field lookups
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
38. The database that will be used if this query is executed now
iexact
choices tuple
db
one-to-one relationship
39. Manager method used to retrieve every object in a model.
lte
all()
Entry.objects.filter(pub_date__range=(start_date - end_date))
pickling
40. 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.
ordered
order_by(*fields)
default
OneToOneField
41. A convenience method for looking up an object with the given kwargs - creating one if necessary.
defer(*fields)
get_or_create(**kwargs)
Field lookups
Entry.objects.filter(id__gt=4)
42. 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
primary_key
ForeignKey
in_bulk(id_list)
43. Lookup type that returns results with a case-sensitive end sequence.
id field
endswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
null
44. If this option is True - Django will store empty values as NULL in the database. Default is False.
save()
values_list(*fields)
choices tuple
null
45. Lookup type that finds a case-sensitive regular expression match.
regex
ManyToManyField
Many-to-many relationship through an intermediate model
id field
46. 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
pk
defer(*fields)
id field
F()
47. 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
filter(**kwargs)
class type
Q()
db
48. This model method saves a model instance to the database. This method has no return value.
get_or_create(**kwargs)
clear() method
save()
pickling
49. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
exists()
__unicode__()
evaluation
count()
50. If True - the table does not permit duplicate values for this field.
iteration
Field lookups
only(*fields)
unique