首页 > 解决方案 > 鹡鸰管理图像和文档标签

问题描述

无论如何如何禁用图像/文档标签?我在我的项目中使用了很多集合,并且任何用户都可以看到来自任何集合的标签这一事实是不受欢迎的,因此我宁愿根本没有标签。我找不到如何将它们禁用给用户看不到它们的方法。

有什么建议吗?

标签: wagtail

解决方案


我找到了一种使用信号编辑文档/图像表单的方法。如果有人感兴趣,我的解决方案如下

from django.dispatch import receiver
from django.db.models.signals import pre_init
from wagtail.documents.models import Document
from wagtail.images.models import Image

@receiver(pre_init, sender=Document)
def document_form_hide_tags(sender, instance=None, created=False, **kwargs):
    '''
    hides tags from the document form
    '''
    Document.admin_form_fields = (
        'title',
        'file',
        'collection',
        # 'tags'
    )


@receiver(pre_init, sender=Image)
def image_form_hide_tags(sender, instance=None, created=False, **kwargs):
    '''
    hides tags from the image form
    '''
    Image.admin_form_fields = (
        'title',
        'file',
        'collection',
        # 'tags',
        'focal_point_x',
        'focal_point_y',
        'focal_point_width',
        'focal_point_height',
    )

推荐阅读