take a look at the following meta implementation, it adds read permissions for all django models that set the MyModelMeta class as a metaclass :
class MyModelMeta(ModelBase):
create abstract django models and set the memeber for the metaclass in MyModelMeta:
class MyAbstractModel(models.Model): __metaclass__ = MyModelMeta class Meta: abstract=True
now create a regular django model, for example:
class SomeModel(MyAbstractModel): someFieldName = models.CharField(max_length=256, db_index=True)
this will create default add / change / delete_somemodel permissions, but it will also add a new read_somemodel permission.
if you also use south, use this to create additional permissions:
from django.db.models import get_app, get_models from django.contrib.auth.management import create_permissions create_permissions(get_app(app), get_models(), 2 if settings.DEBUG else 0)
source share