Reference
QuerySet API reference
update_or_create(defaults=None,create_defaults=None,**kwargs) aupdate_or_create(defaults=None,create_defaults=None,**kwargs) Asynchronous version: aupdate_or_create() A convenience method for updating an object with the given kwargs, creating a new one if necessary. Both create_defaults and defaults are dictionaries of (field, value) pairs.
Reference
QuerySet API reference
… updates the given fields on the provided model instances, generally with one query, and returns the number of objects updated: QuerySet.update() is used to save the changes, so this is more efficient than iterating through the list of models and …
Reference
QuerySet API reference
count() acount() Asynchronous version: acount() Returns an integer representing the number of objects in the database matching the QuerySet.
Reference
QuerySet API reference
If id_list isn’t provided, all objects in the queryset are returned. field_name must be a unique field or a distinct field (if there’s only one field specified in distinct()). field_name defaults to the primary key.
Reference
QuerySet API reference
iterator(chunk_size=None) aiterator(chunk_size=None) Asynchronous version: aiterator() Evaluates the QuerySet (by performing the query) and returns an iterator over the results, or an asynchronous iterator if you call its asynchronous version aiterator.
Reference
QuerySet API reference
See Isolation when using QuerySet.iterator() for more information. The chunk_size parameter controls the size of batches Django retrieves from the database driver.
Reference
QuerySet API reference
latest(*fields) alatest(*fields) Asynchronous version: alatest() Returns the latest object in the table based on the given field(s).
Reference
QuerySet API reference
earliest(*fields) aearliest(*fields) Asynchronous version: aearliest() Works otherwise like latest() except the direction is changed.
Reference
QuerySet API reference
first() afirst() Asynchronous version: afirst() Returns the first object matched by the queryset, or None if there is no matching object.
Reference
QuerySet API reference
last() alast() Asynchronous version: alast() Works like first(), but returns the last object in the queryset.
Reference
QuerySet API reference
aggregate(*args,**kwargs) aaggregate(*args,**kwargs) Asynchronous version: aaggregate() 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.
Reference
QuerySet API reference
exists() aexists() Asynchronous version: aexists() Returns True if the QuerySet contains any results, and False if not.
Reference
QuerySet API reference
contains(obj) acontains(obj) Asynchronous version: acontains() Returns True if the QuerySet contains obj, and False if not. This tries to perform the query in the simplest and fastest way possible.
Reference
QuerySet API reference
… here we update the comments_on and headline fields: The update() 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, not on related models. …
Reference
QuerySet API reference
delete() adelete() Asynchronous version: adelete() Performs an SQL delete query on all rows in the QuerySet and returns the number of objects deleted and a dictionary with the number of deletions per object type.
Reference
QuerySet API reference
classmethodas_manager() Class method that returns an instance of Manager with a copy of the QuerySet’s methods. See Creating a manager with QuerySet methods for more details.
Reference
QuerySet API reference
explain(format=None,**options) aexplain(format=None,**options) Asynchronous version: aexplain() Returns a string of the QuerySet’s execution plan, which details how the database would execute the query, including any indexes or joins that would be used.
Reference
QuerySet API reference
They’re specified as keyword arguments to the QuerySet methods filter(), exclude() and get(). For an introduction, see models and database queries documentation. Django’s built-in lookups are listed below. It is also possible to write custom lookups for model fields.
Reference
QuerySet API reference
In a given iterable; often a list, tuple, or queryset. It’s not a common use case, but strings (being iterables) are accepted.
Reference
QuerySet API reference
Attempts to use > aggregation on date/time fields in SQLite will raise NotSupportedError. NOTE: Aggregation functions return None when used with an empty QuerySet > or group.