polymorphic.managers¶
The manager class for use in the models.
The PolymorphicManager
class¶
-
class
polymorphic.managers.
PolymorphicManager
¶ Bases:
django.db.models.manager.Manager
Manager for PolymorphicModel
Usually not explicitly needed, except if a custom manager or a custom queryset class is to be used.
-
queryset_class
¶ alias of
polymorphic.query.PolymorphicQuerySet
-
get_queryset
()¶ Return a new QuerySet object. Subclasses can override this method to customize the behavior of the Manager.
-
The PolymorphicQuerySet
class¶
-
class
polymorphic.managers.
PolymorphicQuerySet
(*args, **kwargs)¶ Bases:
django.db.models.query.QuerySet
QuerySet for PolymorphicModel
Contains the core functionality for PolymorphicModel
Usually not explicitly needed, except if a custom queryset class is to be used.
-
__init__
(*args, **kwargs)¶ Initialize self. See help(type(self)) for accurate signature.
-
aggregate
(*args, **kwargs)¶ translate the polymorphic field paths in the kwargs, then call vanilla aggregate. We need no polymorphic object retrieval for aggregate => switch it off.
-
annotate
(*args, **kwargs)¶ translate the polymorphic field paths in the kwargs, then call vanilla annotate. _get_real_instances will do the rest of the job after executing the query.
-
bulk_create
(objs, batch_size=None)¶ 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_ids_from_bulk_insert=True). Multi-table models are not supported.
-
defer
(*fields)¶ Translate the field paths in the args, then call vanilla defer.
Also retain a copy of the original fields passed, which we’ll need when we’re retrieving the real instance (since we’ll need to translate them again, as the model will have changed).
-
get_real_instances
(base_result_objects=None)¶ Cast a list of objects to their actual classes.
This does roughly the same as:
return [ o.get_real_instance() for o in base_result_objects ]
but more efficiently.
Return type: PolymorphicQuerySet
-
instance_of
(*args)¶ Filter the queryset to only include the classes in args (and their subclasses).
-
non_polymorphic
()¶ switch off polymorphic behaviour for this query. When the queryset is evaluated, only objects of the type of the base class used for this query are returned.
-
not_instance_of
(*args)¶ Filter the queryset to exclude the classes in args (and their subclasses).
-
only
(*fields)¶ Translate the field paths in the args, then call vanilla only.
Also retain a copy of the original fields passed, which we’ll need when we’re retrieving the real instance (since we’ll need to translate them again, as the model will have changed).
-
order_by
(*field_names)¶ translate the field paths in the args, then call vanilla order_by.
-