db.models.query.QuerySet.db

db The database that will be used if this query is executed now. Note The query parameter to QuerySet exists so that specialized query subclasses such as GeoQuerySet can reconstruct internal query state. The value of the parameter is an opaque representation of that query state and is not part of a public API. To put it simply: if you need to ask, you don’t need to use it.

db.models.query.QuerySet.datetimes()

datetimes(field_name, kind, order='ASC', tzinfo=None) Returns 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. field_name should be the name of a DateTimeField of your model. kind should be either "year", "month", "day", "hour", "minute" or "second". Each datetime.datetime object in the result list is “truncated” to the given type. order, which defaults to 'ASC', should be either 'ASC'

db.models.query.QuerySet.dates()

dates(field, kind, order='ASC') Returns a QuerySet that evaluates to a list of datetime.date objects representing all available dates of a particular kind within the contents of the QuerySet. field should be the name of a DateField of your model. kind should be either "year", "month" or "day". Each datetime.date object in the result list is “truncated” to the given type. "year" returns a list of all distinct year values for the field. "month" returns a list of all distinct year/month value

db.models.query.QuerySet.create()

create(**kwargs) A convenience method for creating an object and saving it all in one step. Thus: p = Person.objects.create(first_name="Bruce", last_name="Springsteen") and: p = Person(first_name="Bruce", last_name="Springsteen") p.save(force_insert=True) are equivalent. The force_insert parameter is documented elsewhere, but all it means is that a new object will always be created. Normally you won’t need to worry about this. However, if your model contains a manual primary key value that

db.models.query.QuerySet.count()

count() Returns an integer representing the number of objects in the database matching the QuerySet. The count() method never raises exceptions. Example: # Returns the total number of entries in the database. Entry.objects.count() # Returns the number of entries whose headline contains 'Lennon' Entry.objects.filter(headline__contains='Lennon').count() A count() call performs a SELECT COUNT(*) behind the scenes, so you should always use count() rather than loading all of the record into Pyt

db.models.query.QuerySet.bulk_create()

bulk_create(objs, batch_size=None) This method inserts the provided list of objects into the database in an efficient manner (generally only 1 query, no matter how many objects there are): >>> Entry.objects.bulk_create([ ... Entry(headline="Django 1.0 Released"), ... Entry(headline="Django 1.1 Announced"), ... Entry(headline="Breaking: Django is awesome") ... ]) This has a number of caveats though: The model’s save() method will not be called, and the pre_save and post_

db.models.query.QuerySet.annotate()

annotate(*args, **kwargs) Annotates each object in the QuerySet with the provided list of query expressions. An expression may be a simple value, a reference to a field on the model (or any related models), or an aggregate expression (averages, sums, etc.) that has been computed over the objects that are related to the objects in the QuerySet. Each argument to annotate() is an annotation that will be added to each object in the QuerySet that is returned. The aggregation functions that are pr

db.models.query.QuerySet.all()

all() Returns a copy of the current QuerySet (or QuerySet subclass). This can be useful in situations where you might want to pass in either a model manager or a QuerySet and do further filtering on the result. After calling all() on either object, you’ll definitely have a QuerySet to work with. When a QuerySet is evaluated, it typically caches its results. If the data in the database might have changed since a QuerySet was evaluated, you can get updated results for the same query by calling

db.models.query.QuerySet.aggregate()

aggregate(*args, **kwargs) Returns a dictionary of aggregate values (averages, sums, etc.) calculated over the QuerySet. Each argument to aggregate() specifies a value that will be included in the dictionary that is returned. The aggregation functions that are provided by Django are described in Aggregation Functions below. Since aggregates are also query expressions, you may combine aggregates with other aggregates or values to create complex aggregates. Aggregates specified using keyword a

db.models.query.QuerySet

class QuerySet(model=None, query=None, using=None) [source] Usually when you’ll interact with a QuerySet you’ll use it by chaining filters. To make this work, most QuerySet methods return new querysets. These methods are covered in detail later in this section. The QuerySet class has two public attributes you can use for introspection: ordered True if the QuerySet is ordered — i.e. has an order_by() clause or a default ordering on the model. False otherwise. db The database that wil