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. Manager method used to retrieve every object in a model.
clear() method
default
filter(**kwargs)
all()
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.
~
default
choices tuple
filter
3. Lookup type that returns results less than or equal to a given value.
lte
|
only(*fields)
help_text
4. Lookup type that returns results with a case-insensitive end sequence.
month
all()
none()
iendswith
5. a QuerySet can be sliced - using Python's array-slicing syntax.
delete()
filter(**kwargs)
slicing
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
6. Returns the most recent object in the table - by date - using the field_name provided as the date field.
isnull
blank
latest(field_name=None)
class attributes
7. Negation operator for Q objects.
Multi-table inheritance
get(**kwargs)
Q(question__istartswith='What')
~
8. If True - this field is the primary key for the model.
latest(field_name=None)
update(**kwargs)
primary_key
distinct()
9. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
gt
all()
select_related()
ordered
10. A convenience method for constructing an object and saving it all in one step.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
reverse()
evaluation
create(**kwargs)
11. The default for this is the name of the child class followed by '_set'.
reverse name
endswith
intermediate models
relationship spanning
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)
Meta class
default
Manager
Model metadata
13. Conjuntion operator for Q objects.
unique
&
add()
ordered
14. To activate your models
blank
==
update()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
15. This method immediately deletes the object and has no return value.
update(**kwargs)
Q(question__istartswith='What')
delete()
Abstract base class
16. 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.
lt
annotate(args - *kwargs)
Restrictions on field names
get(**kwargs)
17. Used to get a QuerySet for a model. This is called 'objects' by default.
class type
blank
null
Manager
18. Can be used to remove all many-to-many relationships for an instance
clear() method
get(**kwargs)
Manager methods
select_related()
19. Lookup type that finds a case-sensitive regular expression match.
one-to-one relationship
intermediate models
regex
db
20. Lookup type that tests for inclusion in a case-sensitive fashion.
contains
using(alias)
model
count()
21. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
Q(question__istartswith='What')
reverse name
all()
iteration
22. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
delete()
Proxy model
many-to-many relationship
23. 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
ordered
intermediate models
null
latest(field_name=None)
24. The database that will be used if this query is executed now
~
annotate(args - *kwargs)
db
iendswith
25. Lookup type that returns results with a case-sensitive start sequence.
filter(**kwargs)
range
startswith
class attributes
26. 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.
Entry.objects.filter(id__in=[1 - 3 - 4])
month
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
order_by(*fields)
27. 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
28. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
many-to-many relationship
delete()
OneToOneField
29. This represents a collection of objects from your database. It can have zero - one or many filters.
Entry.objects.filter(id__in=[1 - 3 - 4])
QuerySet
pickling
ManyToManyField
30. 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.
update(**kwargs)
get_or_create(**kwargs)
model
many-to-one relationship
31. Lookup type that finds a case-insensitive regular expression match.
iregex
filter
&
lt
32. 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
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
none()
exists()
annotate(args - *kwargs)
33. Returns the object matching the given lookup parameters
choices tuple
many-to-one relationship
only(*fields)
get(**kwargs)
34. This query finds all entries with an id in the list [1 - 3 - 4]
Model metadata
exact
select_related()
Entry.objects.filter(id__in=[1 - 3 - 4])
35. Returns a QuerySet that will automatically "follow" foreign-key relationships - selecting that additional related-object data when it executes its query. This is a performance booster which results in (sometimes much) larger queries but means later u
select_related()
DoesNotExist
exact
Field lookups
36. 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
iendswith
class type
lte
isnull
37. 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.
month
choices
iregex
annotate(args - *kwargs)
38. Fields are specified by these
class attributes
class type
pk
Custom model methods
39. 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
delete()
exists()
Restrictions on field names
unique
40. 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.
values_list(*fields)
select_related()
distinct()
Entry.objects.filter(id__gt=4)
41. These methods are intended to do "table-wide" things.
Meta class
values(*fields)
Manager methods
in
42. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
iterator()
using(alias)
model
get_or_create(**kwargs)
43. 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.
pk
related_name
using(alias)
filter(**kwargs)
44. 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
class attributes
Multi-table inheritance
Model metadata
45. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
distinct()
many-to-one relationship
count()
regex
46. Returns a ValuesQuerySet -- a QuerySet that returns dictionaries when used as an iterable - rather than model-instance objects.
Q()
many-to-many relationship
values(*fields)
evaluation
47. 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
Restrictions on field names
add()
defer(*fields)
update(**kwargs)
48. This style of inheritanc is useful when you're subclassing an existing model (perhaps something from another application entirely) and want each model to have its own database table. Here - each model in the hierarchy is a model all by itself.
values_list(*fields)
class type
Entry.objects.filter(pub_date__range=(start_date - end_date))
Multi-table inheritance
49. This query uses an F object to increment the pingback count for every entry in the blog.
Warning
: Invalid argument supplied for foreach() in
/var/www/html/basicversity.com/show_quiz.php
on line
183
50. A Python "magic method" that returns a unicode "representation" of any object.
filter
__unicode__()
clear() method
dates(field - kind - order='ASC')