class QuerySet: (source)
Represent a lazy database lookup for a set of objects.
Class Method | as |
Undocumented |
Method | __aiter__ |
Undocumented |
Method | __and__ |
Undocumented |
Method | __bool__ |
Undocumented |
Method | __class |
Undocumented |
Method | __deepcopy__ |
Don't populate the QuerySet's cache. |
Method | __getitem__ |
Retrieve an item or slice from the set of results. |
Method | __getstate__ |
Undocumented |
Method | __init__ |
Undocumented |
Method | __iter__ |
The queryset iterator protocol uses three nested iterators in the default case: 1. sql.compiler.execute_sql() - Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE) using cursor... |
Method | __len__ |
Undocumented |
Method | __or__ |
Undocumented |
Method | __repr__ |
Undocumented |
Method | __setstate__ |
Undocumented |
Method | __xor__ |
Undocumented |
Async Method | aaggregate |
Undocumented |
Async Method | abulk |
Undocumented |
Async Method | abulk |
Undocumented |
Async Method | acontains |
Undocumented |
Async Method | acount |
Undocumented |
Async Method | acreate |
Undocumented |
Async Method | adelete |
Undocumented |
Async Method | aearliest |
Undocumented |
Async Method | aexists |
Undocumented |
Async Method | aexplain |
Undocumented |
Async Method | afirst |
Undocumented |
Async Method | aget |
Undocumented |
Async Method | aget |
Undocumented |
Method | aggregate |
Return a dictionary containing the calculations (aggregation) over the current queryset. |
Async Method | ain |
Undocumented |
Async Method | aiterator |
An asynchronous iterator over the results from applying this QuerySet to the database. |
Async Method | alast |
Undocumented |
Async Method | alatest |
Undocumented |
Method | alias |
Return a query set with added aliases for extra data or aggregations. |
Method | all |
Return a new QuerySet that is a copy of the current one. This allows a QuerySet to proxy for a model manager in some cases. |
Method | annotate |
Return a query set in which the returned objects have been annotated with extra data or aggregations. |
Async Method | aupdate |
Undocumented |
Async Method | aupdate |
Undocumented |
Method | bulk |
Insert each of the instances into the database. Do *not* call save() on each of the instances, do not send any pre/post_save signals, and do not set the primary key attribute if it is an autoincrement field (except if features... |
Method | bulk |
Update the given fields in each of the given objects in the database. |
Method | complex |
Return a new QuerySet instance with filter_obj added to the filters. |
Method | contains |
Return True if the QuerySet contains the provided obj, False otherwise. |
Method | count |
Perform a SELECT COUNT() and return the number of records as an integer. |
Method | create |
Create a new object with the given kwargs, saving it to the database and returning the created object. |
Method | dates |
Return a list of date objects representing all available dates for the given field_name, scoped to 'kind'. |
Method | datetimes |
Return a list of datetime objects representing all available datetimes for the given field_name, scoped to 'kind'. |
Method | defer |
Defer the loading of data for certain fields until they are accessed. Add the set of deferred fields to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case removal all deferrals. |
Method | delete |
Delete the records in the current QuerySet. |
Method | difference |
Undocumented |
Method | distinct |
Return a new QuerySet instance that will select only distinct results. |
Method | earliest |
Undocumented |
Method | exclude |
Return a new QuerySet instance with NOT (args) ANDed to the existing set. |
Method | exists |
Return True if the QuerySet would have any results, False otherwise. |
Method | explain |
Runs an EXPLAIN on the SQL query this QuerySet would perform, and returns the results. |
Method | extra |
Add extra SQL fragments to the query. |
Method | filter |
Return a new QuerySet instance with the args ANDed to the existing set. |
Method | first |
Return the first object of a query or None if no match is found. |
Method | get |
Perform the query and return a single object matching the given keyword arguments. |
Method | get |
Look up an object with the given kwargs, creating one if necessary. Return a tuple of (object, created), where created is a boolean specifying whether an object was created. |
Method | in |
Return a dictionary mapping each of the given IDs to the object with that ID. If `id_list` isn't provided, evaluate the entire QuerySet. |
Method | intersection |
Undocumented |
Method | iterator |
An iterator over the results from applying this QuerySet to the database. chunk_size must be provided for QuerySets that prefetch related objects. Otherwise, a default chunk_size of 2000 is supplied. |
Method | last |
Return the last object of a query or None if no match is found. |
Method | latest |
Return the latest object according to fields (if given) or by the model's Meta.get_latest_by. |
Method | none |
Return an empty QuerySet. |
Method | only |
Essentially, the opposite of defer(). Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated. |
Method | order |
Return a new QuerySet instance with the ordering changed. |
Method | prefetch |
Return a new QuerySet instance that will prefetch the specified Many-To-One and Many-To-Many related objects when the QuerySet is evaluated. |
Method | query |
Undocumented |
Method | raw |
Undocumented |
Method | resolve |
Undocumented |
Method | reverse |
Reverse the ordering of the QuerySet. |
Method | select |
Return a new QuerySet instance that will select objects with a FOR UPDATE lock. |
Method | select |
Return a new QuerySet instance that will select related objects. |
Method | union |
Undocumented |
Method | update |
Update all elements in the current QuerySet, setting all the given fields to the appropriate values. |
Method | update |
Look up an object with the given kwargs, updating one with defaults if it exists, otherwise create a new one. Return a tuple (object, created), where created is a boolean specifying whether an object was created. |
Method | using |
Select which database this QuerySet should execute against. |
Method | values |
Undocumented |
Method | values |
Undocumented |
Instance Variable | model |
Undocumented |
Property | db |
Return the database used if this query is executed now. |
Property | ordered |
Return True if the QuerySet is ordered -- i.e. has an order_by() clause or a default ordering on the model (or is empty). |
Property | query |
Undocumented |
Static Method | _validate |
Undocumented |
Method | _add |
Update hinting information for use by routers. Add new key/values or overwrite existing key/values. |
Method | _annotate |
Undocumented |
Method | _batched |
Helper method for bulk_create() to insert objs one batch at a time. |
Method | _chain |
Return a copy of the current QuerySet that's ready for another operation. |
Method | _check |
Undocumented |
Method | _check |
Undocumented |
Method | _clone |
Return a copy of the current QuerySet. A lightweight alternative to deepcopy(). |
Method | _combinator |
Undocumented |
Method | _earliest |
Return the earliest object according to fields (if given) or by the model's Meta.get_latest_by. |
Method | _extract |
Prepare `params` for creating a model instance based on the given kwargs; for use by get_or_create(). |
Method | _fetch |
Undocumented |
Method | _filter |
Undocumented |
Method | _filter |
Undocumented |
Method | _has |
Check if this QuerySet has any filtering going on. This isn't equivalent with checking if all objects are present in results, for example, qs[1:]._has_filters() -> False. |
Method | _insert |
Insert a new record for the given model. This provides an interface to the InsertQuery class and is how Model.save() is implemented. |
Method | _iterator |
Undocumented |
Method | _merge |
Keep track of all known related objects from either QuerySet instance. |
Method | _merge |
Check that two QuerySet classes may be merged. |
Method | _next |
Indicate that the next filter call and the one following that should be treated as a single filter. This is only important when it comes to determining when to reuse tables for many-to-many filters. Required so that we can filter naturally on the results of related managers. |
Method | _not |
Undocumented |
Method | _prefetch |
Undocumented |
Method | _prepare |
Undocumented |
Method | _raw |
Delete objects found from the given queryset in single direct SQL query. No signals are sent and there is no protection for cascades. |
Method | _update |
A version of update() that accepts field objects instead of field names. Used primarily for model saving and not intended for use by general code (it requires too much poking around at model internals to be useful at that level). |
Method | _values |
Undocumented |
Instance Variable | _db |
Undocumented |
Instance Variable | _defer |
Undocumented |
Instance Variable | _deferred |
Undocumented |
Instance Variable | _fields |
Undocumented |
Instance Variable | _for |
Undocumented |
Instance Variable | _hints |
Undocumented |
Instance Variable | _iterable |
Undocumented |
Instance Variable | _known |
Undocumented |
Instance Variable | _prefetch |
Undocumented |
Instance Variable | _prefetch |
Undocumented |
Instance Variable | _query |
Undocumented |
Instance Variable | _result |
Undocumented |
Instance Variable | _sticky |
Undocumented |
The queryset iterator protocol uses three nested iterators in the default case: 1. sql.compiler.execute_sql() - Returns 100 rows at time (constants.GET_ITERATOR_CHUNK_SIZE) using cursor.fetchmany(). This part is responsible for doing some column masking, and returning the rows in chunks. 2. sql.compiler.results_iter() - Returns one row at time. At this point the rows are still just tuples. In some cases the return values are converted to Python values at this location. 3. self.iterator() - Responsible for turning the rows into model objects.
Undocumented
Return a dictionary containing the calculations (aggregation) over the current queryset. If args is present the expression is passed as a kwarg using the Aggregate object's default alias.
Return a new QuerySet that is a copy of the current one. This allows a QuerySet to proxy for a model manager in some cases.
Return a query set in which the returned objects have been annotated with extra data or aggregations.
Insert each of the instances into the database. Do *not* call save() on each of the instances, do not send any pre/post_save signals, and do not set the primary key attribute if it is an autoincrement field (except if features.can_return_rows_from_bulk_insert=True). Multi-table models are not supported.
Return a new QuerySet instance with filter_obj added to the filters. filter_obj can be a Q object or a dictionary of keyword lookup arguments. This exists to support framework features such as 'limit_choices_to', and usually it will be more natural to use other methods.
Perform a SELECT COUNT() and return the number of records as an integer. If the QuerySet is already fully cached, return the length of the cached results set to avoid multiple SELECT COUNT(*) calls.
Create a new object with the given kwargs, saving it to the database and returning the created object.
Return a list of date objects representing all available dates for the given field_name, scoped to 'kind'.
Return a list of datetime objects representing all available datetimes for the given field_name, scoped to 'kind'.
Defer the loading of data for certain fields until they are accessed. Add the set of deferred fields to any existing set of deferred fields. The only exception to this is if None is passed in as the only parameter, in which case removal all deferrals.
Add extra SQL fragments to the query.
Look up an object with the given kwargs, creating one if necessary. Return a tuple of (object, created), where created is a boolean specifying whether an object was created.
Return a dictionary mapping each of the given IDs to the object with that ID. If `id_list` isn't provided, evaluate the entire QuerySet.
An iterator over the results from applying this QuerySet to the database. chunk_size must be provided for QuerySets that prefetch related objects. Otherwise, a default chunk_size of 2000 is supplied.
Essentially, the opposite of defer(). Only the fields passed into this method and that are not already specified as deferred are loaded immediately when the queryset is evaluated.
Return a new QuerySet instance that will prefetch the specified Many-To-One and Many-To-Many related objects when the QuerySet is evaluated. When prefetch_related() is called more than once, append to the list of prefetch lookups. If prefetch_related(None) is called, clear the list.
Return a new QuerySet instance that will select related objects. If fields are specified, they must be ForeignKey fields and only those related objects are included in the selection. If select_related(None) is called, clear the list.
Update all elements in the current QuerySet, setting all the given fields to the appropriate values.
Look up an object with the given kwargs, updating one with defaults if it exists, otherwise create a new one. Return a tuple (object, created), where created is a boolean specifying whether an object was created.
Return True if the QuerySet is ordered -- i.e. has an order_by() clause or a default ordering on the model (or is empty).
Helper method for bulk_create() to insert objs one batch at a time.
Undocumented
Prepare `params` for creating a model instance based on the given kwargs; for use by get_or_create().
Check if this QuerySet has any filtering going on. This isn't equivalent with checking if all objects are present in results, for example, qs[1:]._has_filters() -> False.
Insert a new record for the given model. This provides an interface to the InsertQuery class and is how Model.save() is implemented.
Indicate that the next filter call and the one following that should be treated as a single filter. This is only important when it comes to determining when to reuse tables for many-to-many filters. Required so that we can filter naturally on the results of related managers. This doesn't return a clone of the current QuerySet (it returns "self"). The method is only used internally and should be immediately followed by a filter() that does create a clone.
Delete objects found from the given queryset in single direct SQL query. No signals are sent and there is no protection for cascades.