7

Using the polymorphic inlines for Django admin instead of the regular one

This commit is contained in:
Jasper Berghoef
2016-11-22 11:11:37 +01:00
parent 2c7e970bee
commit 9ecc1c47c9
2 changed files with 32 additions and 29 deletions

View File

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