Wagtail Admin多类模型

时间:2019-01-29 11:58:48

标签: python django wagtail

因此,我试图将模型中一个单独类中的其他字段添加到扩展ModelAdmin的wagtail_hook中。

您可以在我的模型中看到有两个类,一个是Report这是主类,另一个是Sender。在Wagtail管理员中,我想将“发件人”内容添加到报告页面。

有没有办法用w做这件事?

这是我的模型。py

class Report(models.Model):

    # Django will set the ID
    Pay_Period_Start_Date   = models.DateTimeField('Pay Period Start Date')
    Pay_Period_End_Date    = models.DateTimeField('Pay Period End Date')

    def __str__(self):
        return "Report for:" + str(self.Pay_Period_Start_Date) + " to " + str(self.Pay_Period_End_Date)


class Sender(models.Model):

    report = models.ForeignKey(Report, on_delete=models.CASCADE, default=None, null=True)
    Family_Name = models.CharField(('Family_Name'), max_length=30, blank=True)
    Given_Name =    models.CharField(('Given_Name'), max_length=30, blank=True)
    Email_Address = models.CharField(('Email_Address'), max_length=30, blank=True)
    Telephone_Number = models.CharField(('Telephone_Number'), max_length=30, blank=True)

这是我的wagtail_hook.py

from wagtail.contrib.modeladmin.options import (
    ModelAdmin, modeladmin_register)
from .models import Report, Sender

class CHModelAdmin(ModelAdmin):
    model = Report
    menu_label = 'Clearing House'  # ditch this to use verbose_name_plural from model
    menu_icon = 'form'  # change as required
    menu_order = 300  # will put in 3rd place (000 being 1st, 100 2nd)
    add_to_settings_menu = False  # or True to add your model to the Settings sub-menu
    exclude_from_explorer = False # or True to exclude pages of this type from Wagtail's explorer view
    list_display = ('Pay_Period_Start_Date', 'Pay_Period_End_Date')
    search_fields = ('Pay_Period_Start_Date')
    list_filter = ('Pay_Period_Start_Date', 'Pay_Period_End_Date')

# Now you just need to register your customised ModelAdmin class with Wagtail
modeladmin_register(CHModelAdmin)

0 个答案:

没有答案