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 greater than or equal to a given value.
filter
choices
one-to-one relationship
gte
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.
latest(field_name=None)
Entry.objects.filter(id__in=[1 - 3 - 4])
default
week_day
3. Returns the object matching the given lookup parameters
exact
exclude(**kwargs)
reverse()
get(**kwargs)
4. 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
5. If this option is True - the field is allowed to be blank. Default is False.
many-to-many relationship
order_by(*fields)
blank
Q()
6. This query deletes all Entry objects with a pub_date year of 2005.
choices
clear() method
Entry.objects.filter(pub_date__year=2005).delete()
class attributes
7. 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
none()
update(**kwargs)
filter
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
8. 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
Custom model methods
unique
update()
select_related()
9. Returns the most recent object in the table - by date - using the field_name provided as the date field.
latest(field_name=None)
blank
select_related()
in
10. 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.
select_related()
delete()
relationship spanning
ForeignKey
11. This query finds all entries between a start date of start_date and an end date of end_date.
isnull
update()
filter(**kwargs)
Entry.objects.filter(pub_date__range=(start_date - end_date))
12. Lookup type that returns results with a case-insensitive start sequence.
F()
|
class attributes
istartswith
13. Keyword shortcut for looking up an object by primary key.
get(**kwargs)
dates(field - kind - order='ASC')
pk
__unicode__()
14. 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
range
exists()
annotate(args - *kwargs)
none()
15. 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.
ManyToManyField
reverse name
clear() method
choices
16. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
filter(**kwargs)
week_day
QuerySet
filter chaining
17. 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.
==
Meta class
using(alias)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
18. These methods are intended to do "table-wide" things.
OneToOneField
QuerySet
choices
Manager methods
19. 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
F()
iteration
Entry.objects.filter(pub_date__range=(start_date - end_date))
intermediate models
20. If True - this field is the primary key for the model.
Q()
primary_key
one-to-one relationship
model
21. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
select_related()
endswith
through argument
year
22. 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.
add()
all()
null
OneToOneField
23. Returns a new QuerySet containing objects that match the given lookup parameters.
aggregate(args - *kwargs)
db
DoesNotExist
filter(**kwargs)
24. When to run syncdb
endswith
help_text
when you add new apps to INSTALLED_APPS
select_related()
25. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
&
all()
get(**kwargs)
26. 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
27. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
gt
ManyToManyField
related_name
MultipleObjectsReturned
28. 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
lt
month
class type
lte
29. This gives your model metadata.
Meta class
class type
iteration
dates(field - kind - order='ASC')
30. Lookup type that returns results less than or equal to a given value.
DoesNotExist
lte
update()
Q()
31. This represents a collection of objects from your database. It can have zero - one or many filters.
|
isnull
slicing
QuerySet
32. 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
all()
through argument
filter chaining
33. 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.
db
id field
ManyToManyField
primary_key
34. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
year
many-to-many relationship
filter
|
35. 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.
in_bulk(id_list)
order_by(*fields)
filter(**kwargs)
reverse()
36. To activate your models
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
month
gte
get_or_create(**kwargs)
37. If this option is True - Django will store empty values as NULL in the database. Default is False.
day
null
range
one-to-one relationship
38. Lookup type that returns results with a case-sensitive end sequence.
save()
endswith
month
get(**kwargs)
39. The database that will be used if this query is executed now
reverse name
db
through argument
select_related()
40. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
db
isnull
iexact
count()
41. 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.
QuerySet
pickling
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
exclude(**kwargs)
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.
count()
model
Meta class
update(**kwargs)
43. Use this method to reverse the order in which a queryset's elements are returned. Calling this method a second time restores the ordering back to the normal direction.
year
istartswith
MultipleObjectsReturned
reverse()
44. 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)
choices
select_related()
save()
45. These add custom "row-level" functionality to your objects. These act on a particular model instance.
iterator()
order_by(*fields)
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Custom model methods
46. 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
save()
id field
relationship spanning
47. Lookup type that returns results with a case-insensitive end sequence.
distinct()
iendswith
Many-to-many relationship through an intermediate model
db
48. Exception raised by get(**kwargs) if more than one item matches the query.
MultipleObjectsReturned
dates(field - kind - order='ASC')
id field
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
49. 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
contains
filter chaining
Proxy model
Manager
50. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
filter(**kwargs)
get(**kwargs)
month
isnull