我的 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 管理员允许添加编辑实验室权限,即编辑、删除和修改实验室。但问题是每个用户都可以访问所有的实验室