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 methods are intended to do "table-wide" things.
DoesNotExist
iexact
Manager methods
week_day
2. A convenience method for looking up an object with the given kwargs - creating one if necessary.
F()
get_or_create(**kwargs)
iexact
latest(field_name=None)
3. Lookup type that returns results with a case-sensitive end sequence.
isnull
exclude(**kwargs)
endswith
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
4. 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.
Entry.objects.filter(id__gt=4)
reverse()
many-to-one relationship
year
5. 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.
gte
gt
Entry.objects.filter(pub_date__year=2005).delete()
using(alias)
6. Lookup type that finds a case-insensitive regular expression match.
latest(field_name=None)
iregex
endswith
contains
7. 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
Entry.objects.filter(pub_date__range=(start_date - end_date))
filter(**kwargs)
Abstract base class
Entry.objects.filter(id__gt=4)
8. Lookup type that returns results less than or equal to a given value.
evaluation
lte
latest(field_name=None)
update(**kwargs)
9. If this option is True - Django will store empty values as NULL in the database. Default is False.
Model metadata
iregex
when you add new apps to INSTALLED_APPS
null
10. This is a criterion that narrow down a QuerySet based on given parameters.
annotate(args - *kwargs)
default
filter
count()
11. This represents a collection of objects from your database. It can have zero - one or many filters.
only(*fields)
endswith
Entry.objects.filter(id__gt=4)
QuerySet
12. 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.
OneToOneField
Many-to-many relationship to self
&
Model metadata
13. 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
help_text
create(**kwargs)
intermediate models
startswith
14. 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
DoesNotExist
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
iexact
relationship spanning
15. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
relationship spanning
Abstract base class
year
ordered
16. 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)
many-to-one relationship
Model metadata
startswith
==
17. 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.
none()
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
aggregate(args - *kwargs)
Many-to-many relationship to self
18. 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
F()
annotate(args - *kwargs)
Entry.objects.filter(pub_date__year=2005).delete()
through argument
19. The default for this is the name of the child class followed by '_set'.
reverse name
create(**kwargs)
get(**kwargs)
get_or_create(**kwargs)
20. Used to get a QuerySet for a model. This is called 'objects' by default.
exists()
Manager
clear() method
iexact
21. Lookup type that returns results greater than or equal to a given value.
gte
QuerySet
pickling
endswith
22. 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.
range
Entry.objects.filter(id__gt=4)
save()
ManyToManyField
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()
defer(*fields)
get_absolute_url()
Abstract base class
24. Lookup type that returns results with a case-insensitive start sequence.
search
MultipleObjectsReturned
istartswith
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
25. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
default
count()
evaluation
iteration
26. A manager method that returns a new QuerySet containing objects that do not match the given lookup parameters.
Entry.objects.filter(pub_date__year=2005).delete()
annotate(args - *kwargs)
select_related()
exclude(**kwargs)
27. 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
update(**kwargs)
iexact
startswith
pk
28. 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.
through argument
pickling
QuerySet
gt
29. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
annotate(args - *kwargs)
pk
Field lookups
MultipleObjectsReturned
30. A convenience method for constructing an object and saving it all in one step.
search
endswith
create(**kwargs)
OneToOneField
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.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
exact
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
F()
32. The database that will be used if this query is executed now
pickling
iendswith
relationship spanning
db
33. 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
ForeignKey
reverse()
related_name
34. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
count()
aggregate(args - *kwargs)
year
Field lookups
35. Here - you can't use add - create - or assignment (i.e. - beatles.members = [...]) to create relationships. You need to specify all the detail for the relationship required by the intermediate model.
Many-to-many relationship through an intermediate model
Restrictions on field names
slicing
create(**kwargs)
36. Keyword shortcut for looking up an object by primary key.
isnull
filter
pk
delete()
37. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
relationship spanning
isnull
year
db
38. If True - the table does not permit duplicate values for this field.
delete()
in
unique
|
39. Lookup type for date/datetime fields that finds a 'day of the week' match.
~
Multi-table inheritance
values_list(*fields)
week_day
40. Exception raised by get(**kwargs) if no items match the query.
model
clear() method
all()
DoesNotExist
41. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
intermediate models
all()
clear() method
42. 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
primary_key
none()
one-to-one relationship
many-to-many relationship
43. 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
44. Fields are specified by these
lte
Proxy model
class attributes
id field
45. 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
Multi-table inheritance
ordered
F()
Entry.objects.filter(pub_date__range=(start_date - end_date))
46. 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
Abstract base class
Meta class
iterator()
in_bulk(id_list)
47. 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
endswith
Field lookups
model
Proxy model
48. 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
49. Lookup type that returns results with a case-sensitive start sequence.
week_day
startswith
ordered
all()
50. a QuerySet can be sliced - using Python's array-slicing syntax.
slicing
iexact
latest(field_name=None)
Custom model methods