Limit ImageChooserPanel to children of current Page?

只愿长相守 提交于 2021-01-29 22:00:53

问题


Our site has users who create PropertyPages, and they upload images about each Property. We want these images to not be shared with other Property or other pages, nor other users' content.

But the ImageChooserPanel has access to ALL images uploaded to the site, and newly uploaded images are available to any other user of that Chooser. I am looking for a way to associate images strongly with the individual page; we may only need the upload, not chose from existing images.

Is there a way to do this, perhaps by using a native Django mechanism? I'd still like to make them Orderable in the edit UI, the renditions, and optional storage to S3 like Wagtail Images.

I'm currently relating the multiple Photos to my PropertyPage like:

class PropertyPage(Page):
    content_panels = [
        InlinePanel("property_photo", min_num=1, max_num=100),
        ...]

class PropertyPhoto(Orderable):
    page = ParentalKey(PropertyPage,
                       on_delete=models.CASCADE,
                       related_name="property_photo")
    image = models.ForeignKey("wagtailimages.Image",
                              on_delete=models.CASCADE,
                              related_name="+")
    panels = [ImageChooserPanel("image")]

Thanks for your help.

来源:https://stackoverflow.com/questions/65204618/limit-imagechooserpanel-to-children-of-current-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!