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. 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.
iteration
iregex
update()
day
2. This gives your model metadata.
Meta class
iendswith
pk
exists()
3. This method immediately deletes the object and has no return value.
year
Manager
delete()
istartswith
4. 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
none()
using(alias)
through argument
get_absolute_url()
5. Lookup type that returns results less than a given value.
startswith
lt
Restrictions on field names
&
6. 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
OneToOneField
Custom model methods
annotate(args - *kwargs)
exclude(**kwargs)
7. 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
class attributes
get_or_create(**kwargs)
many-to-one relationship
8. 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.
Q(question__istartswith='What')
gte
choices tuple
none()
9. Lookup type for date/datetime fields that finds a 'day of the week' match.
week_day
id field
through argument
pk
10. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
|
DoesNotExist
related_name
add()
11. Returns the most recent object in the table - by date - using the field_name provided as the date field.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
latest(field_name=None)
in
range
12. 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.
reverse name
QuerySet
Many-to-many relationship to self
pickling
13. Lookup type that returns results greater than or equal to a given value.
Proxy model
db
gte
Many-to-many relationship to self
14. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
get_or_create(**kwargs)
range
blank
15. 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
16. 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.
get(**kwargs)
ForeignKey
when you add new apps to INSTALLED_APPS
ManyToManyField
17. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
get(**kwargs)
create(**kwargs)
contains
18. 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()
evaluation
count()
Many-to-many relationship through an intermediate model
Manager methods
19. 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)
~
add()
relationship spanning
20. 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
21. 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
choices
Entry.objects.filter(id__in=[1 - 3 - 4])
F()
ManyToManyField
22. Keyword shortcut for looking up an object by primary key.
count()
defer(*fields)
day
pk
23. 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)
Multi-table inheritance
related_name
filter chaining
24. Disjunction operator for Q objects.
|
Restrictions on field names
Multi-table inheritance
Q()
25. This query finds all entries with an id greater than 4.
none()
Entry.objects.filter(id__gt=4)
lte
iregex
26. Manager method used to retrieve every object in a model.
Custom model methods
ManyToManyField
add()
all()
27. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
day
isnull
ManyToManyField
related_name
28. 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
29. 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
OneToOneField
Many-to-many relationship to self
evaluation
30. This model method is used for updating a ManyToManyField.
MultipleObjectsReturned
class type
add()
==
31. If True - the table does not permit duplicate values for this field.
Field lookups
unique
regex
search
32. 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
exists()
defer(*fields)
through argument
reverse name
33. 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.
exact
reverse name
get(**kwargs)
when you add new apps to INSTALLED_APPS
34. Lookup type that returns results greater than a given value.
gt
latest(field_name=None)
update()
Restrictions on field names
35. Evaluates the QuerySet (by performing the query) and returns an iterator over the results. A QuerySet typically caches its results internally so that repeated evaluations do not result in additional queries; this method will instead read results dire
Proxy model
Q(question__istartswith='What')
iterator()
none()
36. Lookup type that returns results in a given list.
day
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
create(**kwargs)
in
37. 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.
delete()
order_by(*fields)
ManyToManyField
delete()
38. If True - this field is the primary key for the model.
save()
add()
QuerySet
primary_key
39. This field is added automatically - but this behavior can be overridden
year
id field
iendswith
ForeignKey
40. A convenience method for looking up an object with the given kwargs - creating one if necessary.
|
iendswith
get_or_create(**kwargs)
add()
41. 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.
get_or_create(**kwargs)
default
get(**kwargs)
create(**kwargs)
42. 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.
F()
help_text
~
Many-to-many relationship to self
43. To activate your models
range
delete()
using(alias)
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
44. A Python "magic method" that returns a unicode "representation" of any object.
values_list(*fields)
__unicode__()
Many-to-many relationship to self
Model metadata
45. Lookup type that returns results with a case-sensitive end sequence.
default
ForeignKey
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
endswith
46. 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.
iterator()
Entry.objects.filter(pub_date__year=2005).delete()
month
many-to-one relationship
47. Lookup type that finds a case-sensitive regular expression match.
gte
OneToOneField
regex
Proxy model
48. This object encapsulates a collection of keyword arguments - with the keys being field lookup types. These objects can be combined using the & and | operators - as well as negated with the ~ operator.
MultipleObjectsReturned
Q()
latest(field_name=None)
Abstract base class
49. Lookup type that tests for inclusion in a case-sensitive fashion.
filter(**kwargs)
null
month
contains
50. This query finds all entries between a start date of start_date and an end date of end_date.
Custom model methods
Entry.objects.filter(pub_date__range=(start_date - end_date))
class attributes
only(*fields)