Third-party applications support

Django-reversion support

Django-reversion works as expected with polymorphic models. However, they require more setup than standard models. We have to face these problems:

  • The children models are not registered in the admin site. You will therefore need to manually register them to django-reversion.
  • Polymorphic models use multi-table inheritance. The django-reversion wiki explains how to deal with this.

Example

The admin Example becomes:

from django.contrib import admin
from polymorphic.admin import PolymorphicParentModelAdmin, PolymorphicChildModelAdmin
import reversion
from reversion import VersionAdmin
from .models import ModelA, ModelB, ModelC


class ModelAChildAdmin(PolymorphicChildModelAdmin):
    base_model = ModelA
    base_form = ...
    base_fieldsets = (
        ...
    )

class ModelBAdmin(VersionAdmin, ModelAChildAdmin):
    # define custom features here

class ModelCAdmin(ModelBAdmin):
    # define custom features here


class ModelAParentAdmin(VersionAdmin, PolymorphicParentModelAdmin):
    base_model = ModelA
    child_models = (
        (ModelB, ModelBAdmin),
        (ModelC, ModelCAdmin),
    )

reversion.register(ModelB, follow=['modela_ptr'])
reversion.register(ModelC, follow=['modelb_ptr'])
admin.site.register(ModelA, ModelAParentAdmin)

Table Of Contents

Previous topic

Custom Managers, Querysets & Manager Inheritance

Next topic

Changelog

This Page