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. 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.
clear() method
aggregate(args - *kwargs)
ordered
order_by(*fields)
2. A Python "magic method" that returns a unicode "representation" of any object.
defer(*fields)
__unicode__()
get_or_create(**kwargs)
QuerySet
3. 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
4. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
slicing
Entry.objects.filter(id__in=[1 - 3 - 4])
Meta class
5. This query finds all entries between a start date of start_date and an end date of end_date.
range
contains
Entry.objects.filter(pub_date__range=(start_date - end_date))
slicing
6. 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
iterator()
defer(*fields)
related_name
~
7. Negation operator for Q objects.
gte
id field
~
defer(*fields)
8. 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.
help_text
slicing
values_list(*fields)
null
9. If this option is True - Django will store empty values as NULL in the database. Default is False.
Q()
through argument
null
QuerySet
10. If True - this field is the primary key for the model.
primary_key
distinct()
Proxy model
exists()
11. 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.
relationship spanning
choices
pk
Q(question__istartswith='What')
12. 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.
DoesNotExist
Entry.objects.filter(pub_date__year=2005).delete()
&
aggregate(args - *kwargs)
13. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
null
blank
class type
14. Performs an SQL update query for the specified fields - and returns the number of rows affected. This method is applied instantly and the only restriction on the QuerySet that is updated is that it can only update columns in the model's main table. F
update(**kwargs)
none()
DoesNotExist
save()
15. Lookup type that returns results with a case-sensitive start sequence.
startswith
gt
latest(field_name=None)
contains
16. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
many-to-one relationship
year
all()
17. This field is added automatically - but this behavior can be overridden
save()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
delete()
id field
18. 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.
pickling
Q()
primary_key
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
19. 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)
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
iendswith
update(**kwargs)
Model metadata
20. 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
21. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Field lookups
related_name
one-to-one relationship
22. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
get_absolute_url()
month
exists()
23. 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
defer(*fields)
using(alias)
delete()
F()
24. 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.
model
aggregate(args - *kwargs)
in
Many-to-many relationship to self
25. 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.
db
clear() method
|
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
26. 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.
Multi-table inheritance
create(**kwargs)
when you add new apps to INSTALLED_APPS
delete()
27. 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.
many-to-one relationship
one-to-one relationship
pickling
only(*fields)
28. Fields are specified by these
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
filter(**kwargs)
related_name
class attributes
29. (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.
delete()
iregex
unique
Restrictions on field names
30. 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.
ManyToManyField
aggregate(args - *kwargs)
in_bulk(id_list)
create(**kwargs)
31. 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
iterator()
iendswith
lte
exists()
32. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
in_bulk(id_list)
many-to-many relationship
get_or_create(**kwargs)
filter(**kwargs)
33. Conjuntion operator for Q objects.
&
search
select_related()
slicing
34. 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
filter(**kwargs)
endswith
select_related()
Entry.objects.filter(pub_date__year=2005).delete()
35. Lookup type for date/datetime fields that finds a 'day of the week' match.
year
defer(*fields)
week_day
__unicode__()
36. Lookup type that returns results with a case-sensitive end sequence.
filter chaining
filter(**kwargs)
values(*fields)
endswith
37. This query deletes all Entry objects with a pub_date year of 2005.
pickling
count()
save()
Entry.objects.filter(pub_date__year=2005).delete()
38. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
filter chaining
model
only(*fields)
pk
39. 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
40. This gives your model metadata.
iteration
filter(**kwargs)
Meta class
unique
41. This is a criterion that narrow down a QuerySet based on given parameters.
ordered
filter
when you add new apps to INSTALLED_APPS
contains
42. Lookup type that finds a case-insensitive regular expression match.
class attributes
many-to-one relationship
Entry.objects.filter(id__in=[1 - 3 - 4])
iregex
43. When to run syncdb
gte
get_or_create(**kwargs)
when you add new apps to INSTALLED_APPS
iregex
44. 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
model
in
__unicode__()
45. Exception raised by get(**kwargs) if more than one item matches the query.
count()
MultipleObjectsReturned
many-to-many relationship
pickling
46. Can be used to remove all many-to-many relationships for an instance
gt
clear() method
through argument
startswith
47. Lookup type that tests for inclusion in a case-sensitive fashion.
clear() method
reverse()
Many-to-many relationship through an intermediate model
contains
48. Lookup type that returns results with a case-insensitive start sequence.
==
day
istartswith
defer(*fields)
49. Lookup type that returns results that fall into an inclusive date range.
evaluation
range
choices tuple
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
50. Lookup type that returns results greater than or equal to a given value.
default
gte
values(*fields)
select_related()