如何在Django中的forms.py中获取当前用户的组?

时间:2017-12-27 20:43:12

标签: django django-models django-forms django-templates

我有一个场景,我需要传递登录用户的地址名称并获取该组中的列表用户。

forms.py - 在下面的代码中我需要传递用户的组而不是 Banglore

class UpateTaskMaster(forms.ModelForm):
def __init__(self, *args, **kwargs):
    super(UpateTaskMaster, self).__init__(*args, **kwargs)
    users = User.objects.filter(groups__name='Banglore')
    self.fields['processor'].choices = [(user.pk, user.get_full_name()) for user in users]
class Meta():
    model  = TaskMaster
    fields = ["sid","tasktype","task_title","task_description","datacenter","status","priority","sourceincident","processingteam","duedate","pid","errorincident",'processor']
    widgets = {
               'sid': forms.TextInput(attrs={'class': 'form-control mr-sm-2'}),
               'task_title':forms.Textarea(attrs={'class': 'materialize-textarea'}),
               'task_description':forms.Textarea(attrs={'class': 'materialize-textarea'}),
               'sourceincident': forms.TextInput(attrs={'class': 'form-control mr-sm-2'}),
               'pid': forms.TextInput(attrs={'class': 'form-control mr-sm-2'}),
               'errorincident': forms.TextInput(attrs={'class': 'form-control mr-sm-2'}),
               'duedate' : forms.TextInput(attrs={'class': 'datepicker'}),
               }

1 个答案:

答案 0 :(得分:0)

使用:

READ_EXTERNAL_STORAGE

然后,您可以根据需要进行迭代