Wagtail - 对ClusterableModel的外键

时间:2016-06-22 14:12:50

标签: django wagtail

我有一个课程模型,选项为ClusterableModel和Staff。员工与课程模型相关,Staf可以选择选项。我以前用普通的django做过类似的事情,但我似乎无法弄清楚如何用Wagtail做到这一点。选项在课程页面上正常显示,但在员工选项卡上显示为空。这是我的模特:

class Option(models.Model):
    name = models.CharField(max_length=255)
    desc = models.CharField(max_length=255, blank=True, null=True)

    class Meta:
        abstract = True

    def __str__(self):
        return self.name

    def save(self, force_insert=False, force_update=False, using=None,
         update_fields=None):
        self.tajuk = self.name.title()

    content_panels = [
        FieldPanel('name'),
        FieldPanel('desc')
    ]


class OptionPage(Orderable, Option):
    page = ParentalKey("Course", related_name='course_option')


class Staf(Orderable):
    page = ParentalKey('course.Course', related_name='pcourse')
    jxr = models.ForeignKey('jxr.Staf',
                        null=True,
                        blank=True,
                        on_delete=models.PROTECT,
                        related_name='+'
                        )

    vegetarian = models.BooleanField(default=False)
    attend = models.BooleanField(default=False)
    reason = models.CharField(max_length=255, blank=True, null=True)
    replacement = models.ForeignKey('jxr.Staf',
                              null=True,
                              blank=True,
                              on_delete=models.PROTECT,
                              related_name='+'
                              )
    option = models.ForeignKey(OptionPage,blank=True, null=True)
    class Meta:
        verbose_name_plural = 'Staf'

    panels = [
        FieldPanel('jxr'),
        FieldPanel('vegetarian'),
        FieldPanel('option'),
        FieldPanel('attend'),
        FieldPanel('reason'),
        FieldPanel('replacement'),
]

class Course(Page):
    tags = ClusterTaggableManager(through=CourseTag, blank=True)
    picture = models.ForeignKey(
        'wagtailimages.Image',
        null=True,
        blank=True,
        on_delete=models.SET_NULL,
        related_name='+'
    )
    State = models.ForeignKey(State, default=1,
                           related_name='+',
                           on_delete=models.PROTECT,
                           )
    location = RichTextField()
    start =  models.DateTimeField("Start",default=timezone.now)
    end = models.DateTimeField("End", default=timezone.now)
    max_staf = models.PositiveIntegerField(default=1)
    intro = StreamField(CourseBlock())
    status = models.CharField(max_length=30, choices=STATUS_KURSUS)

search_fields = Page.search_fields + [
    index.SearchField('title'),
    index.SearchField('intro')]

parent_page_types =['course.CourseIndex']
subpage_types=[]

content_panels = [
    FieldPanel('title', classname="full title"),
    MultiFieldPanel([
        InlinePanel('kat_kursus', label='Category'),
        FieldPanel('tags'),
        InlinePanel('course_option', label='Options')
    ]),
    ImageChooserPanel('picture'),
    FieldPanel('state'),
    FieldPanel('location'),
    FieldPanel('start'),
    FieldPanel('end'),
    FieldPanel('max_staf'),
    StreamFieldPanel('intro'),
    FieldPanel('status'),
]
staf_panel = [
    InlinePanel('pkursus', label='Staf')
]

edit_handler = TabbedInterface([
        ObjectList(content_panels, heading='Content'),
        ObjectList(staf_panel, heading='Staf'),
        ObjectList(Page.promote_panels, heading='Promote'),
        ObjectList(Page.settings_panels, heading='Settings', classname="settings"),
    ])

0 个答案:

没有答案