Wagtail的InlinePanel与非页面模型兼容吗?

时间:2018-11-28 04:48:44

标签: wagtail

我有一个Wagtail非页面模型,我想使用InlinePanel以便可以在父表单中内联编辑多个项目。

class Parent(ClusterableModel):
   panels = [...,
        InlinePanel('child_items')
   ]

class Child(Orderable):
   value = models...
   parent_value = ParentalKey('.Parent', on_delete=models.CASCADE, related_name='child_items')

但不幸的是,嵌入式面板未在wagtail管理界面中呈现。

快速浏览一下代码,看来InlinePanel需要一个Page对象/编辑器,因此我想在这里问是否可以在非InlinePanel上使用StackedInline -Page对象,或者是否有更好的方法在wagtail管理员中对非页面对象进行对象的内联编辑(例如django的<?php session_start(); error_reporting(0); include("databaseConnection.php"); $username = $_SESSION['username']; if($_REQUEST['activity'] == 'logout'){ $username = null; $username =""; unset($username); $_SESSION['username'] = null; $_SESSION['username'] =""; unset($_SESSION['username']); session_destroy(); } if(empty($username)){ header("location: ../Index.php"); } ?> <html> <head> </head> <body> <!--CONTAINER AREA SECTION--> <div class="containerHome"> <!--HEAD SECTION--> <div class="headSection"> <?php include("headSection.php"); ?> </div> <!--HEAD SECTION--> <div class="navSection"> <div class="welcomeTitle">Welcome</div> <div class="tooltip">Contact Us <span class="tooltiptext"> <b>Address:</b> Central Department Of Physics, Kirtipur<br> <b>Phone:</b> 01-4331054 </span> </div> <div class="logoutLink"><a href="home.php?activity=logout">Logout</a></div> </div> <!--LEFT BAR SECTION--> <div class="leftSection"> <?php include("leftSection.php");?> </div> <!--LEFT BAR SECTION--> <!--CONTENT AREA SECTION--> <div class="contentSection"> <?php // CODE FOR PERFORMMING ACTIVITY.. $activity = $_REQUEST['activity']; if($activity) { if(isset($_POST['activity'])) { include("dashboard.php"); } if($activity) { if($activity == 'addMember'){ include("addMember.php"); } if($activity == 'dashboard'){ include("dashboard.php"); } if($activity == 'issueBooks'){ include("issueBooks.php"); } if($activity == 'returnBooks'){ include("returnBooks.php"); } if($activity == 'updateBook'){ $uBookId = $_REQUEST['uBookId']; $return = mysql_num_rows(mysql_query("SELECT bookId From borrow Where bookId = '$uBookId'")); if(empty($return)){ $query = mysql_query("SELECT bookId,title,author,price,publisher From books Where bookId = '$uBookId'"); $result = mysql_fetch_assoc($query); ?> </div> <!--CONTENT AREA SECTION--> <!--RIGHT AREA SECTION--> <div class="rightSection"> <?php include("rightSection.php");?> </div> <!--RIGHT AREA SECTION--> </div> <!--CONTAINER AREA SECTION--> </body> </html>)。

1 个答案:

答案 0 :(得分:0)

如果

InlinePanel在非页面模型上注册为代码段或通过ModelAdmin,则可以在非页面模型上使用。您的代码有效的版本(在新创建的Wagtail项目中进行了测试,其中home/models.py替换为下面的代码):

from django.db import models
from modelcluster.fields import ParentalKey
from modelcluster.models import ClusterableModel

from wagtail.admin.edit_handlers import FieldPanel, InlinePanel
from wagtail.core.models import Page, Orderable
from wagtail.snippets.models import register_snippet

class HomePage(Page):
    pass


@register_snippet
class Parent(ClusterableModel):
    title = models.CharField(max_length=255)
    panels = [
        FieldPanel('title'),
        InlinePanel('child_items', label='Child items'),
    ]

class Child(Orderable):
    parent_value = ParentalKey(Parent, on_delete=models.CASCADE, related_name='child_items')
    value = models.CharField(max_length=255)

    panels = [
        FieldPanel('value'),
    ]