我对 django Guardian 有一些问题。我定义了一个新闻模型
class News(models.Model):
title = models.CharField(_('Title'), max_length=255)
slug = models.SlugField(_('Slug'), unique_for_date='pub_date',)
objects = models.Manager()
featured = FeaturedNewsManager()
link = models.URLField(_('Link'), blank=True, null=True,)
class Meta:
permissions = (('view_news', _('view news')))
然后我尝试将 view_news 权限分配给我的一位用户,我收到以下错误:
>>> from guardian.shortcuts import assign_perm
>>> g = Group.objects.latest('pk')
>>> n = News.objects.get(pk=4)
>>> assign_perm( 'news.view_news', g, n)
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/guardian/shortcuts.py", line 93, in assign_perm
return model.objects.assign_perm(perm, group, obj)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/guardian/managers.py", line 90, in assign_perm
permission = Permission.objects.get(content_type=ctype, codename=perm)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/db/models/manager.py", line 143, in get
return self.get_query_set().get(*args, **kwargs)
File "/home/roberto/.virtualenvs/ve_news/local/lib/python2.7/site-packages/django/db/models/query.py", line 404, in get
self.model._meta.object_name)
DoesNotExist: Permission matching query does not exist.
我已经尝试迁移我的应用程序,但这似乎并没有解决我的问题。请问有什么帮助吗?
谢谢!