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. This field is added automatically - but this behavior can be overridden
id field
db
annotate(args - *kwargs)
DoesNotExist
2. This query finds all entries with an id greater than 4.
Many-to-many relationship through an intermediate model
Entry.objects.filter(id__gt=4)
iexact
slicing
3. This model method is used for updating a ManyToManyField.
month
add()
Entry.objects.filter(pub_date__year=2007).update(headline='Everything is the same')
ManyToManyField
4. 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.
search
count()
Abstract base class
ManyToManyField
5. Lookup type that returns results with a case-sensitive end sequence.
iterator()
related_name
startswith
endswith
6. 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
intermediate models
==
exact
|
7. 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)
==
Model metadata
through argument
range
8. Fields are specified by these
|
~
class attributes
add()
9. 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
clear() method
defer(*fields)
exists()
delete()
10. The database that will be used if this query is executed now
db
istartswith
month
count()
11. Returns the most recent object in the table - by date - using the field_name provided as the date field.
update()
latest(field_name=None)
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
delete()
12. Exception raised by get(**kwargs) if no items match the query.
DoesNotExist
iexact
update(**kwargs)
save()
13. Lookup type for date/datetime fields that finds an exact year match. Takes a four-digit year.
values_list(*fields)
year
update()
exact
14. Lookup type that finds a case-insensitive regular expression match.
day
choices tuple
iregex
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
15. 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.
OneToOneField
isnull
Multi-table inheritance
gte
16. Lookup type that returns results less than a given value.
clear() method
id field
lt
many-to-one relationship
17. A Python "magic method" that returns a unicode "representation" of any object.
__unicode__()
year
choices
model
18. 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
range
blank
Abstract base class
using(alias)
19. Lookup type that yields a case-insensitive match.
in
default
iexact
help_text
20. This represents a collection of objects from your database. It can have zero - one or many filters.
model
iendswith
QuerySet
delete()
21. 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.
ordered
exact
Many-to-many relationship to self
Custom model methods
22. 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
Field lookups
DoesNotExist
class type
annotate(args - *kwargs)
23. 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
Manager
in_bulk(id_list)
search
24. 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.
relationship spanning
Multi-table inheritance
get(**kwargs)
many-to-one relationship
25. Lookup type that returns results less than or equal to a given value.
get(**kwargs)
evaluation
lte
order_by(*fields)
26. 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
when you add new apps to INSTALLED_APPS
through argument
lte
delete()
27. Lookup type that returns results with a case-sensitive start sequence.
startswith
dates(field - kind - order='ASC')
id field
create(**kwargs)
28. This query finds all entries with an id in the list [1 - 3 - 4]
dates(field - kind - order='ASC')
filter chaining
Entry.objects.filter(id__in=[1 - 3 - 4])
one-to-one relationship
29. Operator for comparing two model instances for equality. Behind the scenes - it compares the primary key values of two models.
filter(**kwargs)
gte
iterator()
==
30. 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.
Manager methods
extra(select=None - where=None - params=None - tables=None - order_by=None - select_params=None)
week_day
get_absolute_url()
31. 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.
default
reverse name
F()
month
32. These add custom "row-level" functionality to your objects. These act on a particular model instance.
add()
Manager methods
Custom model methods
intermediate models
33. A convenience method for looking up an object with the given kwargs - creating one if necessary.
get_or_create(**kwargs)
relationship spanning
model
null
34. Lookup type that returns results with a case-insensitive end sequence.
iendswith
default
select_related()
month
35. Exception raised by get(**kwargs) if more than one item matches the query.
intermediate models
year
month
MultipleObjectsReturned
36. Keyword shortcut for looking up an object by primary key.
Q()
DoesNotExist
pk
iexact
37. 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.
update()
in
using(alias)
delete()
38. 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()
intermediate models
isnull
update(**kwargs)
39. Lookup type that corresponds to a boolean full-text search - taking advantage of full-text indexing. This is like contains but is significantly faster due to full-text indexing.
F()
unique
search
using(alias)
40. 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.
Entry.objects.filter(id__gt=4)
iendswith
iregex
pickling
41. Lookup type that takes either True or False and corresponds to SQL queries of IS NULL and IS NOT NULL - respectively.
dates(field - kind - order='ASC')
relationship spanning
isnull
null
42. Can be used to remove all many-to-many relationships for an instance
ordered
Entry.objects.all().update(n_pingbacks=F('n_pingbacks') + 1)
get_or_create(**kwargs)
clear() method
43. This query deletes all Entry objects with a pub_date year of 2005.
Entry.objects.filter(pub_date__year=2005).delete()
in_bulk(id_list)
QuerySet
create(**kwargs)
44. 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
45. True if the QuerySet has an order_by() clause or a default ordering on the model. False otherwise.
Q()
isnull
ordered
primary_key
46. Lookup type that tests for inclusion in a case-sensitive fashion.
year
help_text
contains
reverse name
47. 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.
Q(question__startswith='Who') | ~Q(pub_date__year=2005)
Field lookups
related_name
get(**kwargs)
48. Conjuntion operator for Q objects.
MultipleObjectsReturned
&
contains
pickling
49. 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
__unicode__()
Meta class
DoesNotExist
50. 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
iterator()
Entry.objects.filter(id__gt=4)
filter(**kwargs)
reverse name