我的模型中有一个ForeignKey,它将通过管理员用户角色过滤组织ID。
user_group_validation函数就像这样...
def user_group_validation(request):
var = {}
if request.user.is_authenticated():
groups = request.user.groups.all()
var['group'] = DefaultLandingPage.objects.get(pk=groups).role.name
var['tpl'] = DefaultLandingPage.objects.get(pk=groups).url
return var
else:
return 'sorry, not yet! =('
然后我们通过role_choice_organization函数来获取所提供角色的组织......
def role_choice_organization(self):
var = {}
var = user_group_validation(self.request)
userInc = Users.objects.get(id=self.request.user.id).organization_id.pk
self.request.session['userInc'] = userInc
if var['group'] == 'superuser':
organization = Organizations.objects.all()
if var['group'] == 'admin' or var['group'] == 'user':
organization = Organizations.objects.filter(id=self.request.session['userInc'])
返回组织
最后,我尝试将此组织的值返回到我的ForeignKey查询集中,就像这样......
organization_id = models.ForeignKey(organization, editable=True)
现在我使用此代码得到的错误是"组织未定义"当我尝试将其加载到organization_id ForeignKey
的查询集中时