我的模型中有一个CharField department,它从一组名为department choices的元组中进行选择,并从两个外键字段中选择用户分配给和审批者。我应该如何限制这样的选择,即分配给用户的\u属于与部门相同的组,并且approval \u by是超级用户,同时属于与部门相同的组。你知道吗
型号.py
typechoices = (("DATA",'Data'),("ERROR",'Error'),("NEW_FEATURE",'new feature'),("CHANGE",'change'))
statuschoices =(('open',"OPEN"),('wip',"WIP"),('closed',"CLOSED"),('pending',"PENDING"))
prioritychoices=(('high',"High"),('med','MED'),('low','LOW'))
departmentchoices = (('technical',"Technical"),('allocation',"Allocation"),('operations',"Operations"),('marketing',"Marketing"),('hr',"HR"))
fs = FileSystemStorage(location='media')
def get_upload_file_name(instance,filename):
return "manage/static/manage/%s_%s"%(str(time()).replace('.','_'),filename.replace(' ','_'))
class Request(models.Model):
# user = models.ForeignKey(User,null=True,related_name="user")
department = models.CharField(max_length=20,choices=departmentchoices,default='technical')
request_type = models.CharField(max_length=20,choices=typechoices)
priority=models.CharField(max_length=20,choices=prioritychoices)
description = models.TextField()
sample = models.FileField(storage=fs,blank=True,null=True)
approval_flag = models.BooleanField(default=False)
status = models.CharField(max_length=20,choices=statuschoices,default='pending')
created=models.DateTimeField(auto_now_add=True,null=True)
modified = models.DateTimeField(auto_now=True)
assigned_to = models.ForeignKey(User,blank=True,null=True,limit_choices_to= {'groups__name' : department})
approval_by = models.ForeignKey(User,limit_choices_to={'is_superuser': True,'groups__name' : department},related_name="apprby",blank=True,null=True)
目前没有回答
相关问题 更多 >
编程相关推荐