polymorphic.contrib.extra_views

The extra_views.formsets provides a simple way to handle formsets. The extra_views.advanced provides a method to combine that with a create/update form.

This package provides classes that support both options for polymorphic formsets.

class polymorphic.contrib.extra_views.PolymorphicFormSetView(**kwargs)

Bases: polymorphic.contrib.extra_views.PolymorphicFormSetMixin, extra_views.formsets.ModelFormSetView

A view that displays a single polymorphic formset.

from polymorphic.formsets import PolymorphicFormSetChild


class ItemsView(PolymorphicFormSetView):
    model = Item
    formset_children = [
        PolymorphicFormSetChild(ItemSubclass1),
        PolymorphicFormSetChild(ItemSubclass2),
    ]
formset_class

alias of polymorphic.formsets.models.BasePolymorphicModelFormSet

class polymorphic.contrib.extra_views.PolymorphicInlineFormSet(parent_model, request, instance, view_kwargs=None, view=None)

Bases: polymorphic.contrib.extra_views.PolymorphicFormSetMixin, extra_views.advanced.InlineFormSetFactory

An inline to add to the inlines of the CreateWithInlinesView and UpdateWithInlinesView class.

from polymorphic.formsets import PolymorphicFormSetChild


class ItemsInline(PolymorphicInlineFormSet):
    model = Item
    formset_children = [
        PolymorphicFormSetChild(ItemSubclass1),
        PolymorphicFormSetChild(ItemSubclass2),
    ]


class OrderCreateView(CreateWithInlinesView):
    model = Order
    inlines = [ItemsInline]

    def get_success_url(self):
        return self.object.get_absolute_url()
formset_class

alias of polymorphic.formsets.models.BasePolymorphicInlineFormSet

class polymorphic.contrib.extra_views.PolymorphicInlineFormSetView(**kwargs)

Bases: polymorphic.contrib.extra_views.PolymorphicFormSetMixin, extra_views.formsets.InlineFormSetView

A view that displays a single polymorphic formset - with one parent object. This is a variation of the extra_views package classes for django-polymorphic.

from polymorphic.formsets import PolymorphicFormSetChild


class OrderItemsView(PolymorphicInlineFormSetView):
    model = Order
    inline_model = Item
    formset_children = [
        PolymorphicFormSetChild(ItemSubclass1),
        PolymorphicFormSetChild(ItemSubclass2),
    ]
formset_class

alias of polymorphic.formsets.models.BasePolymorphicInlineFormSet