File: admin.py

package info (click to toggle)
django-polymorphic 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 892 kB
  • sloc: python: 6,784; javascript: 263; makefile: 137
file content (40 lines) | stat: -rw-r--r-- 1,096 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from django.contrib import admin

from polymorphic.admin import PolymorphicInlineSupportMixin, StackedPolymorphicInline

from .models import BankPayment, CreditCardPayment, Order, Payment, SepaPayment


class CreditCardPaymentInline(StackedPolymorphicInline.Child):
    model = CreditCardPayment


class BankPaymentInline(StackedPolymorphicInline.Child):
    model = BankPayment


class SepaPaymentInline(StackedPolymorphicInline.Child):
    model = SepaPayment


class PaymentInline(StackedPolymorphicInline):
    """
    An inline for a polymorphic model.
    The actual form appearance of each row is determined by
    the child inline that corresponds with the actual model type.
    """

    model = Payment
    child_inlines = (CreditCardPaymentInline, BankPaymentInline, SepaPaymentInline)


@admin.register(Order)
class OrderAdmin(PolymorphicInlineSupportMixin, admin.ModelAdmin):
    """
    Admin for orders.
    The inline is polymorphic.
    To make sure the inlines are properly handled,
    the ``PolymorphicInlineSupportMixin`` is needed to
    """

    inlines = (PaymentInline,)