Skip to content

Commit

Permalink
Add django-polymorphic integration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
fdintino committed Apr 3, 2019
1 parent 25b2870 commit ae19a68
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 7 deletions.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Contents
quickstart
why_use
customization
integrations
contributing
changelog

Expand Down
88 changes: 88 additions & 0 deletions docs/integrations.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
============
Integrations
============

django-polymorphic
==================

Quickstart
----------

Support for `django-polymorphic`_ is currently in beta. To use polymorphic
inlines with django-nested-admin follow the steps for
`setting up django-polymorphic admin inline integration`_. The instructions
are identical with django-nested-admin, except that the classes you would
normally import from ``polymorphic.admin`` should instead be imported from
``nested_admin`` and the classes themselves should be prefixed with
``Nested`` For example:

.. code-block:: python
# Instead of these imports
from django.contrib.admin import ModelAdmin
from polymorphic.admin import (
PolymorphicInlineSupportMixin, StackedPolymorphicInline)
# One should import:
from nested_admin import (
NestedModelAdmin,
NestedPolymorphicInlineSupportMixin, NestedStackedPolymorphicInline)
The polymorphic inlines used with django-nested-admin can have other inlines
nested inside them, or even other polymorphic inlines. The only requirement
is that all ModelAdmin and InlineAdmin classes inherit from the appropriate
nested version.

.. _django-polymorphic: https://django-polymorphic.readthedocs.io/en/stable/index.html
.. _setting up django-polymorphic admin inline integration: https://django-polymorphic.readthedocs.io/en/stable/admin.html#inline-models

Example
-------

.. code-block:: python
from django.contrib import admin
import nested_admin
from .models import (
Store, Customer, GuestCustomer, LoggedInCustomer, OrderItem, Product, WishListItem,
Order, WishList, Payment, CreditCardPayment, BankPayment)
class PaymentInline(nested_admin.NestedStackedPolymorphicInline):
model = Payment
class CreditCardPaymentInline(nested_admin.NestedStackedPolymorphicInline.Child):
model = CreditCardPayment
class BankPayment(nested_admin.NestedStackedPolymorphicInline.Child):
model = BankPayment
child_inlines = (CreditCardPaymentInline, BankPayment)
class ProductInline(nested_admin.NestedStackedInline):
model = Product
class WishListItemInline(nested_admin.NestedStackedInline):
model = WishListItem
sortable_field_name = 'position'
class WishListInline(nested_admin.NestedStackedInline):
model = WishList
inlines = [WishListItemInline]
class OrderItemInline(nested_admin.NestedStackedInline):
model = OrderItem
class OrderInline(nested_admin.NestedTabularInline):
model = Order
inlines = [OrderItemInline, PaymentInline]
class CustomerInline(nested_admin.NestedStackedPolymorphicInline):
model = Customer
inlines = [OrderInline]
class GuestCustomerInline(nested_admin.NestedStackedPolymorphicInline.Child):
model = GuestCustomer
class LoggedInCustomerInline(nested_admin.NestedStackedPolymorphicInline.Child):
model = LoggedInCustomer
inlines = [WishListInline]
child_inlines = (GuestCustomerInline, LoggedInCustomerInline)
@admin.register(Store)
class StoreAdmin(nested_admin.NestedPolymorphicModelAdmin):
inlines = [CustomerInline]
7 changes: 0 additions & 7 deletions docs/modules.rst

This file was deleted.

0 comments on commit ae19a68

Please sign in to comment.