Working inline panels for segments
Signed-off-by: Jasper Berghoef <jasper.berghoef@gmail.com>
This commit is contained in:
@ -1,40 +1,29 @@
|
|||||||
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):
|
class TimeRuleAdminInline(admin.TabularInline):
|
||||||
"""Inline the Time Rule into the administration interface for segments"""
|
"""Inline the Time Rule into the administration interface for segments"""
|
||||||
model = models.TimeRule
|
model = models.TimeRule
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class ReferralRuleAdminInline(StackedPolymorphicInline.Child):
|
class ReferralRuleAdminInline(admin.TabularInline):
|
||||||
"""
|
"""Inline the Referral Rule into the administration interface for segments"""
|
||||||
Inline the Referral Rule into the administration interface for segments
|
|
||||||
"""
|
|
||||||
model = models.ReferralRule
|
model = models.ReferralRule
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
class VisitCountRuleAdminInline(StackedPolymorphicInline.Child):
|
class VisitCountRuleAdminInline(admin.TabularInline):
|
||||||
"""
|
"""Inline the Visit Count Rule into the administration interface for segments"""
|
||||||
Inline the Visit Count Rule into the administration interface for segments
|
|
||||||
"""
|
|
||||||
model = models.VisitCountRule
|
model = models.VisitCountRule
|
||||||
extra = 0
|
extra = 0
|
||||||
|
|
||||||
|
|
||||||
model = models.AbstractBaseRule
|
class SegmentAdmin(admin.ModelAdmin):
|
||||||
child_inlines = (
|
"""Add the inlines to the Segment admin interface"""
|
||||||
TimeRuleAdminInline,
|
inlines = (TimeRuleAdminInline, ReferralRuleAdminInline, VisitCountRuleAdminInline)
|
||||||
ReferralRuleAdminInline,
|
|
||||||
VisitCountRuleAdminInline,
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@admin.register(models.Segment)
|
admin.site.register(models.Segment, SegmentAdmin)
|
||||||
class SegmentAdmin(PolymorphicInlineSupportMixin, admin.ModelAdmin):
|
|
||||||
inlines = (RulesInline,)
|
|
||||||
|
76
src/personalisation/migrations/0031_auto_20161130_1224.py
Normal file
76
src/personalisation/migrations/0031_auto_20161130_1224.py
Normal file
@ -0,0 +1,76 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# Generated by Django 1.10.3 on 2016-11-30 11:24
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
import django.db.models.deletion
|
||||||
|
import modelcluster.fields
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('personalisation', '0030_personalisablepage_is_segmented'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='abstractbaserule',
|
||||||
|
name='polymorphic_ctype',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='abstractbaserule',
|
||||||
|
name='segment',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='referralrule',
|
||||||
|
name='abstractbaserule_ptr',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='timerule',
|
||||||
|
name='abstractbaserule_ptr',
|
||||||
|
),
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='visitcountrule',
|
||||||
|
name='abstractbaserule_ptr',
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='referralrule',
|
||||||
|
name='id',
|
||||||
|
field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='referralrule',
|
||||||
|
name='segment',
|
||||||
|
field=modelcluster.fields.ParentalKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='personalisation_referralrule_related', related_query_name='personalisation_referralrules', to='personalisation.Segment'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='timerule',
|
||||||
|
name='id',
|
||||||
|
field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='timerule',
|
||||||
|
name='segment',
|
||||||
|
field=modelcluster.fields.ParentalKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='personalisation_timerule_related', related_query_name='personalisation_timerules', to='personalisation.Segment'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='visitcountrule',
|
||||||
|
name='id',
|
||||||
|
field=models.AutoField(auto_created=True, default=0, primary_key=True, serialize=False, verbose_name='ID'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='visitcountrule',
|
||||||
|
name='segment',
|
||||||
|
field=modelcluster.fields.ParentalKey(default=0, on_delete=django.db.models.deletion.CASCADE, related_name='personalisation_visitcountrule_related', related_query_name='personalisation_visitcountrules', to='personalisation.Segment'),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
migrations.DeleteModel(
|
||||||
|
name='AbstractBaseRule',
|
||||||
|
),
|
||||||
|
]
|
@ -22,12 +22,10 @@ from wagtail.wagtailcore.models import Page
|
|||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class AbstractBaseRule(PolymorphicModel):
|
class AbstractBaseRule(models.Model):
|
||||||
"""Base for creating rules to segment users with"""
|
"""Base for creating rules to segment users with"""
|
||||||
segment = ParentalKey(
|
segment = ParentalKey(
|
||||||
'personalisation.Segment',
|
'personalisation.Segment',
|
||||||
# TODO: Make the related names accessible to wagtail admin
|
|
||||||
# for inlining them.
|
|
||||||
related_name="%(app_label)s_%(class)s_related",
|
related_name="%(app_label)s_%(class)s_related",
|
||||||
related_query_name="%(app_label)s_%(class)ss"
|
related_query_name="%(app_label)s_%(class)ss"
|
||||||
)
|
)
|
||||||
@ -39,6 +37,9 @@ class AbstractBaseRule(PolymorphicModel):
|
|||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "Segmentation rule"
|
return "Segmentation rule"
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
abstract = True
|
||||||
|
|
||||||
|
|
||||||
@python_2_unicode_compatible
|
@python_2_unicode_compatible
|
||||||
class TimeRule(AbstractBaseRule):
|
class TimeRule(AbstractBaseRule):
|
||||||
@ -175,6 +176,14 @@ class Segment(ClusterableModel):
|
|||||||
'personalisation_timerule_related',
|
'personalisation_timerule_related',
|
||||||
label=_("Time rule"), min_num=0, max_num=1
|
label=_("Time rule"), min_num=0, max_num=1
|
||||||
),
|
),
|
||||||
|
InlinePanel(
|
||||||
|
'personalisation_referralrule_related',
|
||||||
|
label=_("Referral rule"), min_num=0, max_num=1
|
||||||
|
),
|
||||||
|
InlinePanel(
|
||||||
|
'personalisation_visitcountrule_related',
|
||||||
|
label=_("Visit count rule"), min_num=0, max_num=1
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
Reference in New Issue
Block a user