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.


Add fieldguard to INSTALLED_APPS:


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/
import fieldguard

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/
import fieldguard
from shop.models import Product

class ProductAdmin(admin.ModelAdmin)
    model = Product
    ..., ProductAdmin)

Update django permissions db table:

./ 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):
  • 0 downloads in the last day
  • 19 downloads in the last week
  • 76 downloads in the last month