djblets.db.query¶
-
class
LocalDataQuerySet
(data)[source]¶ Bases:
object
A QuerySet that operates on generic data provided by the caller.
This can be used in some circumstances when code requires a QuerySet, but where the data doesn’t come from the database. The caller can instantiate one of these and provide it.
This doesn’t perform full support for all of QuerySet’s abilities. It does, however, support the following basic functions:
- all
- clone
- count
- exclude
- filter
- get
- order_by
- prefetch_related
- select_related
As well as the operators expected by consumers of QuerySet, such as __len__ and __iter__.
This is particularly handy with WebAPIResource.
-
exclude
(**kwargs)[source]¶ Returns a queryset excluding items from this queryset.
The result will be a LocalDataQuerySet that contains all items from this queryset that do not contain attributes with values matching those that were passed to this function as keyword arguments.
-
filter
(**kwargs)[source]¶ Returns a queryset filtering items from this queryset.
The result will be a LocalDataQuerySet that contains all items from this queryset that contain attributes with values matching those that were passed to this function as keyword arguments.
-
get
(**kwargs)[source]¶ Returns a single result from this queryset.
This will return a single result from the list of items in this queryset. If keyword arguments are provided, they will be used to filter the queryset down.
There must be only one item in the queryset matching the given criteria, or a MultipleObjectsReturned will be raised. If there are no items, then an ObjectDoesNotExist will be raised.
-
order_by
(*attrs, **kwargs)[source]¶ Returns a queryset ordering items by the specified attributes.
The result will be a LocalDataQuerySet that contains all items from this queryset ordered by the attributes specified. If multiple attributes are specified, the items are sorted by the first attribute and ties are broken by the other following attributes.
All items are sorted in ascending order. To specify a descending order, an attribute must have a ‘-‘ prepended to the name, such as -attribute_A.
Stub for compatibility with QuerySet.prefetch_related.
This will simply return a clone of this queryset.
Stub for compatibility with QuerySet.select_related.
This will simply return a clone of this queryset.
Allow for chaining select_related calls on a queryset.
This is a workaround for Django 1.6’s inability to chain calls to
QuerySet.select_related()
. When using Django 1.6, the returned queryset will be a special type that handles the chaining. On Django 1.7 and higher, querysets support this natively, so this function will just return the queryset as-is.Parameters: queryset (django.db.models.query.QuerySet) – The queryset to make chainable. Returns: A queryset that allows for chaining. Return type: django.db.models.query.QuerySet