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 with a case-sensitive start sequence.
count()
in_bulk(id_list)
iterator()
startswith
2. This query deletes all Entry objects with a pub_date year of 2005.
search
Entry.objects.filter(pub_date__year=2005).delete()
&
class type
3. A convenience method for looking up an object with the given kwargs - creating one if necessary.
only(*fields)
select_related()
get_or_create(**kwargs)
OneToOneField
4. Negation operator for Q objects.
__unicode__()
range
get_or_create(**kwargs)
~
5. 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()
get(**kwargs)
gt
6. 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.
filter(**kwargs)
one-to-one relationship
get_absolute_url()
in_bulk(id_list)
7. 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
8. 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.
contains
Entry.objects.filter(pub_date__year=2005).delete()
reverse()
Custom model methods
9. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
year
filter(**kwargs)
many-to-many relationship
ordered
10. Lookup type that returns results that fall into an inclusive date range.
dates(field - kind - order='ASC')
reverse()
range
Field lookups
11. The default for this is the name of the child class followed by '_set'.
reverse name
dates(field - kind - order='ASC')
get_absolute_url()
none()
12. This method immediately deletes the object and has no return value.
year
delete()
many-to-one relationship
save()
13. 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
DoesNotExist
|
pickling
none()
14. 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
when you add new apps to INSTALLED_APPS
intermediate models
get(**kwargs)
Multi-table inheritance
15. Fields are specified by these
class attributes
default
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
filter(**kwargs)
16. Defined by a OneToOneField. You use it just like any other Field type: by including it as a class attribute of your model.
Custom model methods
regex
one-to-one relationship
delete()
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.
Many-to-many relationship to self
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
month
latest(field_name=None)
18. Used to get a QuerySet for a model. This is called 'objects' by default.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Manager
evaluation
dates(field - kind - order='ASC')
19. Sometimes - the Django query syntax by itself can't easily express a complex WHERE clause. For these edge cases - Django provides this QuerySet modifier -- a hook for injecting specific clauses into the SQL generated by a QuerySet.
iteration
filter(**kwargs)
values(*fields)
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
20. A Python "magic method" that returns a unicode "representation" of any object.
Entry.objects.filter(id__in=[1 - 3 - 4])
__unicode__()
delete()
get_or_create(**kwargs)
21. Lookup type that finds a case-sensitive regular expression match.
istartswith
Field lookups
regex
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
22. 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
year
filter chaining
select_related()
contains
23. 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.
null
startswith
related_name
exact
24. 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
week_day
Proxy model
filter(**kwargs)
25. Lookup type that yields a case-insensitive match.
delete()
iexact
|
startswith
26. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
lt
startswith
isnull
Q(question__istartswith='What')
27. 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
save()
one-to-one relationship
values_list(*fields)
defer(*fields)
28. 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.
filter
choices
Multi-table inheritance
delete()
29. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
create(**kwargs)
Q()
Many-to-many relationship through an intermediate model
ordered
30. Defined by a ManyToManyField. You use it just like any other Field type: by including it as a class attribute of your model.
Custom model methods
blank
many-to-many relationship
values_list(*fields)
31. If True - the table does not permit duplicate values for this field.
unique
Field lookups
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
db
32. A QuerySet is iterable - and it executes its database query the first time you iterate over it.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
Manager
iteration
get(**kwargs)
33. These are specified as keyword arguments to the QuerySet methods filter() - exclude() and get(). These take the form field__lookuptype=value .
Field lookups
many-to-one relationship
Entry.objects.filter(id__in=[1 - 3 - 4])
null
34. Returns a copy of the current QuerySet (or QuerySet subclass you pass in). This can be useful in some situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. You can safely call all() on
month
slicing
all()
Abstract base class
35. Lookup type that returns results greater than a given value.
ForeignKey
Entry.objects.filter(pub_date__range=(start_date - end_date))
gt
Field lookups
36. A Manager method that returns a new QuerySet containing objects that match the given lookup parameters.
choices
Entry.objects.filter(pub_date__year=2005).delete()
filter(**kwargs)
Manager
37. 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.
in
pickling
startswith
year
38. If True - this field is the primary key for the model.
iexact
exact
primary_key
Manager methods
39. These methods are intended to do "table-wide" things.
reverse name
Manager methods
update(**kwargs)
filter(**kwargs)
40. Lookup type that returns results with a case-sensitive end sequence.
endswith
Many-to-many relationship to self
defer(*fields)
week_day
41. This represents a collection of objects from your database. It can have zero - one or many filters.
filter
Multi-table inheritance
Manager methods
QuerySet
42. Manager method used to retrieve every object in a model.
Q()
all()
order_by(*fields)
class attributes
43. Lookup type for date/datetime fields that finds an exact month match. Takes an integer 1 (January) through 12
many-to-many relationship
month
Field lookups
iendswith
44. To activate your models
ManyToManyField
clear() method
filter chaining
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
45. Conjuntion operator for Q objects.
Manager
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
&
related_name
46. Returns an integer representing the number of objects in the database matching the QuerySet. This never raises exceptions.
count()
order_by(*fields)
__unicode__()
filter(**kwargs)
47. Returns a new QuerySet containing objects that match the given lookup parameters.
edit your settings file and change the INSTALLED_APPS setting to add the name of the module that contains your models.py.
F()
filter(**kwargs)
ordered
48. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
annotate(args - *kwargs)
slicing
evaluation
49. This field is added automatically - but this behavior can be overridden
reverse name
intermediate models
OneToOneField
id field
50. 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
ManyToManyField
clear() method