skip to navigation
skip to content

Not Logged In

django-field-guard 0.1

Add per field permissions

This app allows to add permissions for models' fields. The users who don't have permission to edit specified field will have this field read-only in django admin.

Installation

Add fieldguard to INSTALLED_APPS:

# settings.py
INSTALLED_APPS = (
    ...
    'django.contrib.admin',
    'fieldguard',
)

Set @fieldguard.guard(field1, field2, ...) or @fieldguard.guard() decorator for desired model. Those fields field1, field2 etc. will be protected by the newly created rule:

# shop/models.py
...
import fieldguard

...
@fieldguard.guard('name')
class Product(models.Model):
    name = models.CharField(max_length=255)
    description = models.TextField(blank=True)
    quantity = models.PositiveIntegerField()
    price = models.PositiveIntegerField()

Set @fieldguard.enforce decorator for model's admin class. DO NOT FORGET TO ADD model which must specify the model class corresponding to current admin class. Set it even if the admin class is not InlineAdmin:

# shop/admin.py
...
import fieldguard
from shop.models import Product

...
@fieldguard.enforce()
class ProductAdmin(admin.ModelAdmin)
    model = Product
    ...

admin.site.register(Product, ProductAdmin)

Update django permissions db table:

./manage.py fgsync

Now go to the django admin page and edit any user's permissions. You will see there something like Can edit <model_name>[<field>]. From the example above, the rule will be Can edit Product[name].

Now any user who doesn't have the permission Can edit Product[name] sees field name as readonly.

 
File Type Py Version Uploaded on Size
django-field-guard-0.1.tar.gz (md5) Source 2014-02-21 4KB
  • Downloads (All Versions):
  • 7 downloads in the last day
  • 45 downloads in the last week
  • 185 downloads in the last month