polymorphic.managers

The manager class for use in the models.

The PolymorphicManager class

class polymorphic.managers.PolymorphicManager(queryset_class=None, *args, **kwrags)

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 PolymorphicQuerySet

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.

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.

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(*args, **kwargs)

translate the field paths in the args, then call vanilla order_by.