I want to define some custom permissions on an abstract model class that would then be inherited by all child classes, and rather than give the permissions a generic object name that could apply to any subclassed model type, I would like to essentially use the verbose_name_plural
property of the child model as part of the permission names and description (e.g. ('view_classname', 'Can view classname')
), emulating Django's default behavior.
So, what I would be hoping to do would be something like this (which doesn't work, since verbose_name_plural
is not defined in this context):
class AbstractModel(models.Model):
class Meta:
abstract = True
permissions = (
(u'view_%ss' % verbose_name_plural, u'Can view %s' % verbose_name_plural),
)
(This problem is also described at http://code.djangoproject.com/ticket/10686, which includes a patch that implements dynamic replacement of %(class)s
in permission definitions, but this patch was never accepted and my production environment does not allow for patching Django.)
Could you accomplish this with a class decorator instead of an abstract model class?