【问题标题】:add custom user permission in django在 django 中添加自定义用户权限
【发布时间】:2013-02-27 03:01:12
【问题描述】:

我的 models.py 中有以下代码

from django.db import models

# Create your models here.
class LabName(models.Model):
    labsname=models.CharField(max_length=30,unique=True)
    #room_number=models.CharField(max_length=3)
    def __unicode__(self):
     return self.labsname
STAT=(('W','Working'),('N','Not Working'))
class ComponentDescription(models.Model):
    lab_Title=models.ForeignKey('Labname')
    component_Name = models.CharField(max_length=30)
    description = models.TextField(max_length=200)
    qty = models.IntegerField()
    purchased_Date = models.DateField()
    status = models.CharField(max_length=1,choices=STAT)
    to_Do = models.CharField(max_length=30,blank=True) 
    remarks = models.CharField(max_length=30)


    def __unicode__(self):
        return self.component_Name

我的 admin.py 中有以下内容

from django.contrib import admin
from Lab_inventory.models import ComponentDescription,LabName

class ComponentDescriptionInline(admin.TabularInline):
    model = ComponentDescription
    extra=0

class LabNameAdmin(admin.ModelAdmin):
        inlines = [
        ComponentDescriptionInline,
    ]

class ComponentDescriptionAdmin(admin.ModelAdmin):
    list_display=('lab_Title','component_Name','description','qty','purchased_Date','status','to_Do','remarks')
        list_filter=('lab_Title','status','purchased_Date')
admin.site.register(LabName, LabNameAdmin)
admin.site.register(ComponentDescription,ComponentDescriptionAdmin)

我想为用户分配自定义权限。我的意思是不同的用户只能修改分配给他们的实验室。Django 管理员允许添加编辑实验室权限,即编辑、删除和修改实验室。但问题是每个用户可以访问所有实验室

【问题讨论】:

    标签: django django-models django-admin django-views


    【解决方案1】:

    如果我正确理解了这个问题,那么您正在尝试控制每个对象的权限。

    这应该会有所帮助: Adding per-object permissions to django admin

    我还听说你可以使用 django-guardian 包来做到这一点,虽然我从未尝试过: http://pythonhosted.org/django-guardian/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-17
      • 2013-09-09
      • 2010-12-24
      • 2014-01-10
      • 1970-01-01
      • 2014-03-25
      • 2022-11-04
      相关资源
      最近更新 更多