Using the polymorphic inlines for Django admin instead of the regular one
This commit is contained in:
@ -1,36 +1,40 @@
|
|||||||
from django.contrib import admin
|
from django.contrib import admin
|
||||||
|
|
||||||
from personalisation import models
|
from personalisation import models
|
||||||
|
from polymorphic.admin import PolymorphicInlineSupportMixin, StackedPolymorphicInline
|
||||||
|
|
||||||
|
class RulesInline(StackedPolymorphicInline):
|
||||||
|
|
||||||
|
class TimeRuleAdminInline(StackedPolymorphicInline.Child):
|
||||||
|
"""Inline the Time Rule into the administration interface for segments"""
|
||||||
|
model = models.TimeRule
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class TimeRuleAdminInline(admin.TabularInline):
|
class ReferralRuleAdminInline(StackedPolymorphicInline.Child):
|
||||||
"""Inline the Time Rule into the administration interface for segments"""
|
"""
|
||||||
model = models.TimeRule
|
Inline the Referral Rule into the administration interface for segments
|
||||||
extra = 0
|
"""
|
||||||
|
model = models.ReferralRule
|
||||||
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class ReferralRuleAdminInline(admin.TabularInline):
|
class VisitCountRuleAdminInline(StackedPolymorphicInline.Child):
|
||||||
"""
|
"""
|
||||||
Inline the Referral Rule into the administration interface for segments
|
Inline the Visit Count Rule into the administration interface for segments
|
||||||
"""
|
"""
|
||||||
model = models.ReferralRule
|
model = models.VisitCountRule
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class VisitCountRuleAdminInline(admin.TabularInline):
|
model = models.AbstractBaseRule
|
||||||
"""
|
child_inlines = (
|
||||||
Inline the Visit Count Rule into the administration interface for segments
|
TimeRuleAdminInline,
|
||||||
"""
|
ReferralRuleAdminInline,
|
||||||
model = models.VisitCountRule
|
VisitCountRuleAdminInline,
|
||||||
extra = 0
|
|
||||||
|
|
||||||
|
|
||||||
class SegmentAdmin(admin.ModelAdmin):
|
|
||||||
"""Add the inlines to the Segment admin interface"""
|
|
||||||
inlines = (
|
|
||||||
TimeRuleAdminInline, ReferralRuleAdminInline,
|
|
||||||
VisitCountRuleAdminInline
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
admin.site.register(models.Segment, SegmentAdmin)
|
@admin.register(models.Segment)
|
||||||
|
class SegmentAdmin(PolymorphicInlineSupportMixin, admin.ModelAdmin):
|
||||||
|
inlines = (RulesInline,)
|
||||||
|
@ -14,10 +14,9 @@ from modelcluster.fields import ParentalKey
|
|||||||
from modelcluster.models import ClusterableModel
|
from modelcluster.models import ClusterableModel
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
from wagtail.utils.decorators import cached_classmethod
|
from wagtail.utils.decorators import cached_classmethod
|
||||||
from wagtail.wagtailadmin.edit_handlers import (FieldPanel, FieldRowPanel,
|
from wagtail.wagtailadmin.edit_handlers import (
|
||||||
InlinePanel, MultiFieldPanel,
|
FieldPanel, FieldRowPanel, InlinePanel, MultiFieldPanel, ObjectList,
|
||||||
ObjectList, PageChooserPanel,
|
PageChooserPanel, TabbedInterface)
|
||||||
TabbedInterface)
|
|
||||||
from wagtail.wagtailadmin.forms import WagtailAdminPageForm
|
from wagtail.wagtailadmin.forms import WagtailAdminPageForm
|
||||||
from wagtail.wagtailcore.models import Page
|
from wagtail.wagtailcore.models import Page
|
||||||
|
|
||||||
@ -26,7 +25,7 @@ from wagtail.wagtailcore.models import Page
|
|||||||
class AbstractBaseRule(PolymorphicModel):
|
class AbstractBaseRule(PolymorphicModel):
|
||||||
"""Base for creating rules to segment users with"""
|
"""Base for creating rules to segment users with"""
|
||||||
segment = ParentalKey(
|
segment = ParentalKey(
|
||||||
'Segment',
|
'personalisation.Segment',
|
||||||
# TODO: Make the related names accesible to wagtail admin
|
# TODO: Make the related names accesible to wagtail admin
|
||||||
# for inlining them.
|
# for inlining them.
|
||||||
related_name="%(app_label)s_%(class)s_related",
|
related_name="%(app_label)s_%(class)s_related",
|
||||||
|
Reference in New Issue
Block a user