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 less than or equal to a given value.
clear() method
week_day
unique
lte
2. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
iteration
month
unique
id field
3. 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.
save()
default
update()
intermediate models
4. If this option is True - Django will store empty values as NULL in the database. Default is False.
~
regex
null
relationship spanning
5. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
reverse name
pk
delete()
count()
6. To activate your models
update()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
|
all()
7. 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
8. This query finds all entries between a start date of start_date and an end date of end_date.
Q()
Entry.objects.filter(pub_date__year=2005).delete()
db
Entry.objects.filter(pub_date__range=(start_date - end_date))
9. 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.
lt
OneToOneField
annotate(args - *kwargs)
dates(field - kind - order='ASC')
10. Exception raised by get(**kwargs) if no items match the query.
ForeignKey
DoesNotExist
|
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
11. 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.
through argument
exact
filter(**kwargs)
search
12. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
iteration
istartswith
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
create(**kwargs)
13. 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.
choices
using(alias)
ForeignKey
==
14. Lookup type for date/datetime fields that finds an exact day match.
day
endswith
reverse name
unique
15. Each one of these is a Python class that subclasses django.db.models.Model. Each attribute of one of these represents a database field.
model
evaluation
relationship spanning
none()
16. 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
17. Keyword shortcut for looking up an object by primary key.
Many-to-many relationship through an intermediate model
~
Q(question__istartswith='What')
pk
18. Negation operator for Q objects.
~
many-to-one relationship
one-to-one relationship
only(*fields)
19. If True - the table does not permit duplicate values for this field.
clear() method
unique
update()
one-to-one relationship
20. 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
21. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
relationship spanning
==
year
filter(**kwargs)
22. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
|
==
Entry.objects.filter(pub_date__year=2005).delete()
Meta class
23. 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
default
pickling
values_list(*fields)
24. This model method saves a model instance to the database. This method has no return value.
save()
Custom model methods
range
pk
25. This model method is used for updating a ManyToManyField.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
add()
through argument
annotate(args - *kwargs)
26. Can be used to remove all many-to-many relationships for an instance
get(**kwargs)
day
clear() method
contains
27. Disjunction operator for Q objects.
|
many-to-one relationship
defer(*fields)
evaluation
28. 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.
&
reverse()
aggregate(args - *kwargs)
none()
29. 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.
iendswith
db
choices tuple
get(**kwargs)
30. Lookup type that returns results that fall into an inclusive date range.
iregex
Custom model methods
MultipleObjectsReturned
range
31. Lookup type that returns results with a case-sensitive start sequence.
startswith
pickling
gt
primary_key
32. Lookup type that returns results with a case-sensitive end sequence.
latest(field_name=None)
id field
week_day
endswith
33. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
distinct()
MultipleObjectsReturned
year
clear() method
34. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
update(**kwargs)
search
OneToOneField
QuerySet
35. Conjuntion operator for Q objects.
pk
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
&
Restrictions on field names
36. 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
defer(*fields)
Many-to-many relationship through an intermediate model
Entry.objects.filter(id__gt=4)
pickling
37. 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
Proxy model
reverse()
Entry.objects.filter(id__in=[1 - 3 - 4])
none()
38. 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
month
Entry.objects.filter(id__gt=4)
year
none()
39. 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)
startswith
pickling
model
Model metadata
40. These add custom "row-level" functionality to your objects. These act on a particular model instance.
Q()
help_text
iendswith
Custom model methods
41. 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.
choices tuple
db
exists()
in_bulk(id_list)
42. 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
43. Lookup type that returns results greater than a given value.
regex
gt
ManyToManyField
delete()
44. 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
values(*fields)
endswith
all()
update(**kwargs)
45. A convenience method for constructing an object and saving it all in one step.
Entry.objects.filter(pub_date__year=2005).delete()
create(**kwargs)
Q(question__istartswith='What')
Entry.objects.filter(pub_date__range=(start_date - end_date))
46. Adds to each object in the QuerySet with the provided list of aggregate values (averages - sums - etc) that have been computed over the objects that are related to the objects in the QuerySet. Each argument to this is content that will be added to ea
Entry.objects.filter(pub_date__range=(start_date - end_date))
annotate(args - *kwargs)
istartswith
db
47. 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.
Q()
regex
many-to-one relationship
choices
48. 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.
get_absolute_url()
all()
reverse()
db
49. 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
in_bulk(id_list)
exists()
iexact
all()
50. 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
endswith
F()
add()