| 1 |
from django.contrib import admin |
| 2 |
|
| 3 |
from polymorphic.admin import PolymorphicInlineSupportMixin, StackedPolymorphicInline |
| 4 |
|
| 5 |
from .models import BankPayment, CreditCardPayment, Order, Payment, SepaPayment |
| 6 |
|
| 7 |
|
| 8 |
class CreditCardPaymentInline(StackedPolymorphicInline.Child): |
| 9 |
model = CreditCardPayment |
| 10 |
|
| 11 |
|
| 12 |
class BankPaymentInline(StackedPolymorphicInline.Child): |
| 13 |
model = BankPayment |
| 14 |
|
| 15 |
|
| 16 |
class SepaPaymentInline(StackedPolymorphicInline.Child): |
| 17 |
model = SepaPayment |
| 18 |
|
| 19 |
|
| 20 |
class PaymentInline(StackedPolymorphicInline): |
| 21 |
""" |
| 22 |
An inline for a polymorphic model. |
| 23 |
The actual form appearance of each row is determined by |
| 24 |
the child inline that corresponds with the actual model type. |
| 25 |
""" |
| 26 |
|
| 27 |
model = Payment |
| 28 |
child_inlines = (CreditCardPaymentInline, BankPaymentInline, SepaPaymentInline) |
| 29 |
|
| 30 |
|
| 31 |
@admin.register(Order) |
| 32 |
class OrderAdmin(PolymorphicInlineSupportMixin, admin.ModelAdmin): |
| 33 |
""" |
| 34 |
Admin for orders. |
| 35 |
The inline is polymorphic. |
| 36 |
To make sure the inlines are properly handled, |
| 37 |
the ``PolymorphicInlineSupportMixin`` is needed to |
| 38 |
""" |
| 39 |
|
| 40 |
inlines = (PaymentInline,) |