我有一个带有此模型的 Annonce 页面:
class AnnoncePage(Page):
date = models.DateField("Date de publication", blank=True, null=True)
description = RichTextField(features=['h2', 'h3', 'bold', 'italic', 'link', 'hr', 'ol', 'ul'], blank=True)
lieu = models.CharField(blank=True, max_length=200)
surface = models.PositiveSmallIntegerField(blank=True, null=True)
nb_pieces = models.PositiveSmallIntegerField(blank=True, null=True)
prix_affiché_index = models.CharField(blank=True, max_length=200, null=True)
conditions_vente_et_prix = RichTextField(blank=True, features=['h2', 'h3', 'bold', 'italic', 'link', 'hr', 'ol', 'ul'])
def main_image(self):
gallery_item = self.gallery_images.first()
if gallery_item:
return gallery_item.image
else:
return None
content_panels = Page.content_panels + [
FieldPanel('date'),
InlinePanel('gallery_images', label="Gallery images"),
FieldPanel('lieu', classname="full"),
FieldPanel('surface', classname="full"),
FieldPanel('nb_pieces', classname="full"),
FieldPanel('description', classname="full"),
FieldPanel('prix_affiché_index', classname="full"),
FieldPanel('conditions_vente_et_prix', classname="full")
]
promote_panels = []
settings_panels = []
max_count = 20
class AnnoncePageGalleryImage(Orderable):
page = ParentalKey(AnnoncePage, on_delete=models.SET_NULL, related_name='gallery_images', null=True)
image = models.ForeignKey(
'wagtailimages.Image', on_delete=models.SET_NULL, related_name='+', null=True
)
panels = [
ImageChooserPanel('image')
]
如何在删除 Annonce 页面本身后自动删除 Annonce 页面的图像?我需要更改模型吗?