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. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Restrictions on field names
istartswith
Field lookups
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
2. Returns a new QuerySet containing objects that match the given lookup parameters.
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
latest(field_name=None)
filter(**kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
3. 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.
Meta class
help_text
many-to-one relationship
delete()
4. Lookup type that finds a case-sensitive regular expression match.
pk
filter(**kwargs)
regex
filter
5. This query deletes all Entry objects with a pub_date year of 2005.
default
dates(field - kind - order='ASC')
Entry.objects.filter(pub_date__range=(start_date - end_date))
Entry.objects.filter(pub_date__year=2005).delete()
6. (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.
Meta class
pickling
model
Restrictions on field names
7. Lookup type that returns results in a given list.
db
in
Abstract base class
pickling
8. 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
Model metadata
Abstract base class
default
defer(*fields)
9. If you are using this attribute on a ForeignKey or ManyToManyField - you must always specify a unique reverse name for the field.
many-to-one relationship
blank
related_name
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
10. This method is more or less the opposite of defer(). You call it with the fields that should not be deferred when retrieving a model. If you have a model where almost all the fields need to be deferred - using this method to specify the complementary
only(*fields)
dates(field - kind - order='ASC')
range
related_name
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.
get(**kwargs)
exact
defer(*fields)
gte
12. This is a criterion that narrow down a QuerySet based on given parameters.
filter
all()
id field
get_or_create(**kwargs)
13. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
exclude(**kwargs)
Entry.objects.filter(id__gt=4)
slicing
filter(**kwargs)
14. 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.
~
choices
get(**kwargs)
annotate(args - *kwargs)
15. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
exclude(**kwargs)
exact
Multi-table inheritance
many-to-many relationship
16. 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.
ManyToManyField
many-to-many relationship
Many-to-many relationship through an intermediate model
startswith
17. 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
get(**kwargs)
intermediate models
id field
F()
18. 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
19. 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
save()
isnull
order_by(*fields)
exists()
20. 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
Abstract base class
intermediate models
count()
21. Used to get a QuerySet for a model. This is called 'objects' by default.
Meta class
latest(field_name=None)
pk
Manager
22. Lookup type that tests for inclusion in a case-sensitive fashion.
gte
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
contains
get(**kwargs)
23. Performs an SQL delete query on all rows in the QuerySet. This method is applied instantly. You cannot call this method on a QuerySet that has had a slice taken or can otherwise no longer be filtered.
delete()
endswith
exists()
dates(field - kind - order='ASC')
24. Keyword shortcut for looking up an object by primary key.
annotate(args - *kwargs)
pk
regex
Proxy model
25. 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
26. Lookup type that yields a case-insensitive match.
&
clear() method
ManyToManyField
iexact
27. Returns a new QuerySet that uses SELECT DISTINCT in its SQL query. This eliminates duplicate rows from the query results.
evaluation
latest(field_name=None)
annotate(args - *kwargs)
distinct()
28. Negation operator for Q objects.
get_or_create(**kwargs)
delete()
select_related()
~
29. A manager method which returns a single object. If there are no results that match the query - this method will raise a DoesNotExist exception. If more than one item matches this query - the method will raise MultipleObjectsReturned.
order_by(*fields)
get(**kwargs)
month
iendswith
30. 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
through argument
&
range
all()
31. Lookup type that finds a case-insensitive regular expression match.
startswith
contains
iexact
iregex
32. Lookup type that returns results with a case-sensitive start sequence.
startswith
iterator()
latest(field_name=None)
choices tuple
33. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
in_bulk(id_list)
when you add new apps to INSTALLED_APPS
iteration
get(**kwargs)
34. The default for this is the name of the child class followed by '_set'.
Manager
reverse name
annotate(args - *kwargs)
blank
35. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
get_absolute_url()
count()
Manager
create(**kwargs)
36. 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.
==
lt
using(alias)
pk
37. Disjunction operator for Q objects.
Manager
only(*fields)
|
range
38. This query finds all entries with an id in the list [1 - 3 - 4]
Entry.objects.filter(id__in=[1 - 3 - 4])
~
count()
primary_key
39. 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
40. This represents a collection of objects from your database. It can have zero - one or many filters.
distinct()
QuerySet
many-to-one relationship
get_absolute_url()
41. 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.
order_by(*fields)
OneToOneField
ordered
count()
42. 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.
order_by(*fields)
create(**kwargs)
latest(field_name=None)
class type
43. This query finds all entries with an id greater than 4.
QuerySet
count()
Entry.objects.filter(id__gt=4)
iexact
44. 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
45. These add custom "row-level" functionality to your objects. These act on a particular model instance.
lte
ordered
Custom model methods
QuerySet
46. These methods are intended to do "table-wide" things.
pk
null
Manager methods
OneToOneField
47. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
F()
Field lookups
search
month
48. Lookup type that returns results less than a given value.
lt
|
filter(**kwargs)
DoesNotExist
49. 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()
pk
evaluation
Entry.objects.filter(pub_date__year=2005).delete()
Multi-table inheritance
50. Takes the ouput of one filter and uses it as input for another filter. This works because a refinement of a QuerySet is itself a QuerySet.
intermediate models
|
update()
filter chaining