7

Working inline panels for segments

Signed-off-by: Jasper Berghoef <jasper.berghoef@gmail.com>
This commit is contained in:
Jasper Berghoef
2016-11-30 12:29:56 +01:00
parent 7306863fd8
commit 0a5789ea43
3 changed files with 106 additions and 32 deletions

View File

@ -1,40 +1,29 @@
from django.contrib import admin
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 ReferralRuleAdminInline(StackedPolymorphicInline.Child):
"""
Inline the Referral Rule into the administration interface for segments
"""
model = models.ReferralRule
extra = 0
class TimeRuleAdminInline(admin.TabularInline):
"""Inline the Time Rule into the administration interface for segments"""
model = models.TimeRule
extra = 0
class VisitCountRuleAdminInline(StackedPolymorphicInline.Child):
"""
Inline the Visit Count Rule into the administration interface for segments
"""
model = models.VisitCountRule
extra = 0
class ReferralRuleAdminInline(admin.TabularInline):
"""Inline the Referral Rule into the administration interface for segments"""
model = models.ReferralRule
extra = 0
model = models.AbstractBaseRule
child_inlines = (
TimeRuleAdminInline,
ReferralRuleAdminInline,
VisitCountRuleAdminInline,
)
class VisitCountRuleAdminInline(admin.TabularInline):
"""Inline the Visit Count Rule into the administration interface for segments"""
model = models.VisitCountRule
extra = 0
@admin.register(models.Segment)
class SegmentAdmin(PolymorphicInlineSupportMixin, admin.ModelAdmin):
inlines = (RulesInline,)
class SegmentAdmin(admin.ModelAdmin):
"""Add the inlines to the Segment admin interface"""
inlines = (TimeRuleAdminInline, ReferralRuleAdminInline, VisitCountRuleAdminInline)
admin.site.register(models.Segment, SegmentAdmin)