在Django / Mezzanine中为用户添加站点权限

时间:2016-07-21 15:33:16

标签: django django-admin

我不知道如何在Mezzanine中添加此模型的权限:

class SitePermission(models.Model):
    """
    Permission relationship between a user and a site that's
    used instead of ``User.is_staff``, for admin and inline-editing
    access.
    """

    user = models.OneToOneField(user_model_name, verbose_name=_("Author"),
    related_name="%(class)ss")
    sites = models.ManyToManyField("sites.Site", blank=True,
                               verbose_name=_("Sites"))

    class Meta:
        verbose_name = _("Site permission")
        verbose_name_plural = _("Site permissions")

如何在视图中将特定用户添加到特定网站?我没有找到任何关于此的文件。

1 个答案:

答案 0 :(得分:0)

以下是如何操作:

from mezzanine.core.models import SitePermission
siteperms = SitePermission.objects.create(user=user)
siteperms.sites.add(site)