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. 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.
filter
iteration
in
ManyToManyField
2. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
update()
|
Many-to-many relationship through an intermediate model
3. Lookup type that returns results greater than a given value.
gt
unique
dates(field - kind - order='ASC')
blank
4. This class type is useful when you just want to use the parent class to hold information that you don't want to have to type out for each child model. This class isn't going to ever be used in isolation. When it is used as a base class for other mode
iexact
Abstract base class
Manager methods
range
5. 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.
iterator()
Restrictions on field names
choices tuple
day
6. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
==
Model metadata
many-to-one relationship
Restrictions on field names
7. Lookup type that returns results less than or equal to a given value.
week_day
lte
db
startswith
8. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
OneToOneField
count()
distinct()
day
9. This query finds all entries between a start date of start_date and an end date of end_date.
Entry.objects.filter(pub_date__range=(start_date - end_date))
in
filter(**kwargs)
values(*fields)
10. Fields are specified by these
F()
search
&
class attributes
11. Returns the object matching the given lookup parameters
filter chaining
get(**kwargs)
filter(**kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
12. A convenience method for constructing an object and saving it all in one step.
filter chaining
Many-to-many relationship through an intermediate model
create(**kwargs)
~
13. Lookup type that returns results in a given list.
search
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
count()
in
14. Manager method used to retrieve every object in a model.
all()
Many-to-many relationship through an intermediate model
Proxy model
get(**kwargs)
15. 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.
filter(**kwargs)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
Abstract base class
pickling
16. Accomplish this by using the field name of related fields across models - separated by double underscores - until you get to the field you want. For example - to get all Entry objects with a Blog whose name is 'Beatles Blog': Entry.objects.filter(blo
Entry.objects.filter(id__in=[1 - 3 - 4])
latest(field_name=None)
search
relationship spanning
17. This query finds all entries with an id greater than 4.
get_or_create(**kwargs)
Entry.objects.filter(id__gt=4)
startswith
gt
18. When to run syncdb
MultipleObjectsReturned
annotate(args - *kwargs)
reverse name
when you add new apps to INSTALLED_APPS
19. Lookup type that finds a case-insensitive regular expression match.
model
iregex
values(*fields)
latest(field_name=None)
20. 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
class attributes
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
21. 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.
Field lookups
in_bulk(id_list)
values_list(*fields)
day
22. 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
id field
class attributes
only(*fields)
F()
23. 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
defer(*fields)
many-to-many relationship
Custom model methods
24. 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.
none()
Field lookups
class attributes
25. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
isnull
db
values(*fields)
clear() method
26. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
lte
get(**kwargs)
through argument
27. This method immediately deletes the object and has no return value.
OneToOneField
endswith
Entry.objects.filter(id__in=[1 - 3 - 4])
delete()
28. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
get_absolute_url()
Field lookups
null
Q()
29. 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
delete()
intermediate models
filter
evaluation
30. 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
many-to-one relationship
exists()
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Meta class
31. 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.
iendswith
OneToOneField
exact
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
32. Extra text to be displayed under the field on the object's admin form to provide assistance to users. It's useful for documentation even if your object doesn't have an admin form.
isnull
filter(**kwargs)
exists()
help_text
33. 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.
Proxy model
default
Q(question__istartswith='What')
month
34. 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
help_text
model
defer(*fields)
Field lookups
35. 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
choices tuple
get_absolute_url()
annotate(args - *kwargs)
endswith
36. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
pickling
exclude(**kwargs)
intermediate models
null
37. 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
38. The default for this is the name of the child class followed by '_set'.
reverse name
Entry.objects.filter(pub_date__year=2005).delete()
model
latest(field_name=None)
39. 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()
help_text
none()
evaluation
distinct()
40. Used to get a QuerySet for a model. This is called 'objects' by default.
defer(*fields)
range
unique
Manager
41. 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()
pickling
evaluation
month
42. 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.
none()
update()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
model
43. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
latest(field_name=None)
==
count()
related_name
44. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
one-to-one relationship
values_list(*fields)
iteration
==
45. Lookup type that tests for inclusion in a case-sensitive fashion.
search
F()
contains
all()
46. This gives your model metadata.
Model metadata
when you add new apps to INSTALLED_APPS
Meta class
count()
47. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
iexact
many-to-many relationship
pk
week_day
48. 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.
defer(*fields)
~
week_day
in_bulk(id_list)
49. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
class type
startswith
year
MultipleObjectsReturned
50. 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.
create(**kwargs)
Abstract base class
ManyToManyField
OneToOneField