Skip to content
Back to top
View this page
Edit this page

# polymorphic.query

QuerySet for PolymorphicModel

class polymorphic.query.PolymorphicModelIterable

  Bases: `ModelIterable`

  ModelIterable for PolymorphicModel

  Yields real instances if qs.polymorphic_disabled is False, otherwise acts like a regular ModelIterable.

class polymorphic.query.PolymorphicQuerySet

  Bases: `QuerySet`

  QuerySet for PolymorphicModel

  Contains the core functionality for PolymorphicModel

  Usually not explicitly needed, except if a custom queryset class is to be used.

  classmethod as_manager()

    Override base `as_manager()` to return a manager extended from `polymorphic.managers.PolymorphicManager`.

  __init__(*args, **kwargs)
  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, ignore_conflicts=False)

    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.

  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).

  delete()

    Deletion will be done non-polymorphically because Django’s multi-table deletion mechanism is already walking the class hierarchy and producing a correct deletion graph. Introducing polymorphic querysets into the deletion process disrupts the model hierarchy/relationship traversal.

  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.

polymorphic.query.transmogrify(cls, obj)

  Upcast a class to a different type without asking questions.

polymorphic.query.Polymorphic_QuerySet_objects_per_request = 2000

  The maximum number of objects requested per db-request by the polymorphic queryset.iterator() implementation