Python 带有内联对象的Wagtail(Django)代码段-关系相关输入数据的自定义验证

Python 带有内联对象的Wagtail(Django)代码段-关系相关输入数据的自定义验证,python,django,wagtail,Python,Django,Wagtail,我有一个摇尾片段,其中有一个由家长密钥关联的模型。我想根据这两个模型进行清理和验证。一旦父模型已经保存,我就可以访问子模型的clean方法,但之前不能。如果我尝试强制执行内联对象的minu_num,这会阻止对象保存。在子对象的clean方法期间引发的错误不会在前端显示详细信息,只是“由于错误,代码段无法保存。” 一点背景-我想能够添加区域的图像显示内容模糊时,悬停在 如何在从父模型访问属性时清除内联模型,然后向用户显示自定义错误消息 @register_snippet class ImageMa

我有一个摇尾片段,其中有一个由家长密钥关联的模型。我想根据这两个模型进行清理和验证。一旦父模型已经保存,我就可以访问子模型的
clean
方法,但之前不能。如果我尝试强制执行内联对象的
minu_num
,这会阻止对象保存。在子对象的
clean
方法期间引发的错误不会在前端显示详细信息,只是“由于错误,代码段无法保存。”

一点背景-我想能够添加区域的图像显示内容模糊时,悬停在

如何在从父模型访问属性时清除内联模型,然后向用户显示自定义错误消息

@register_snippet
class ImageMap(ClusterableModel):
    image = models.ForeignKey(
        'wagtailimages.Image',
        on_delete=models.SET_NULL,
        null=True,
        blank=True,
        related_name='+',
    ),
    panels = [
        ImageChooserPanel('image'),
        InlinePanel('regions', heading='Hoverable regions', min_num=1, ),
    ]


class ImageRegion(Orderable):
    image_map = ParentalKey('info_site.ImageMap', related_name='regions')
    blurb = RichTextField(max_length=2000)
    left = models.IntegerField()
    top = models.IntegerField()
    right = models.IntegerField()
    bottom = models.IntegerField()
    panels = [
        FieldPanel('blurb'),
        MultiFieldPanel([         
            # This doesn't appear to render as a MultiFieldPanel
            FieldPanel('left'),
            FieldPanel('top'),
            FieldPanel('right'),
            FieldPanel('bottom'),
        ],
)]
    def clean(self):
        super(ImageRegion, self).clean()
        image_width = self.image_map.image.width      # Cannot access parent image_map instance on create
        image_height = self.image_map.image.height
        image_width = self.image_map.image.width
        if any([
            self.top == self.bottom,
            self.top > self.bottom,
            self.top > image_height,
            self.bottom > image_height,
        ]):
            # This ValidationError gets thrown but only error displayed is 
              "The snippet could not be saved due to errors."; 
              Need verbose ValidationError shown
            raise ValidationError(
                'Coordinate top must be less than coordinate bottom; both must be less that image height of %s px' % image_height)