Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python django中许多字段的clean_formField的返回类型是什么?我可以从函数返回列表吗_Python_Django - Fatal编程技术网

Python django中许多字段的clean_formField的返回类型是什么?我可以从函数返回列表吗

Python django中许多字段的clean_formField的返回类型是什么?我可以从函数返回列表吗,python,django,Python,Django,在bootstrap标记输入javascript插件的帮助下,我将许多字段改为令牌字段。然后我得到逗号(,)分隔主键作为输入。从分隔符逗号(,)拆分后,我得到了确切对象的实例。现在了解如何将这些对象添加到manytomany字段。我试着返回列表,但不起作用 这是我的表格课 class EventRegistrationForm(forms.ModelForm): participants = forms.CharField(widget=forms.TextInput(attrs={'a

在bootstrap标记输入javascript插件的帮助下,我将许多字段改为令牌字段。然后我得到逗号(,)分隔主键作为输入。从分隔符逗号(,)拆分后,我得到了确切对象的实例。现在了解如何将这些对象添加到manytomany字段。我试着返回列表,但不起作用

这是我的表格课

class EventRegistrationForm(forms.ModelForm):
    participants = forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off', 'data-role':'tagsinput'}),required=True)

    class Meta:
        model=EventRegistration
        fields=['event', 'participants', 'teamName', 'feePaid']

    def clean_feePaid(self):
        feepaid=self.cleaned_data.get('feePaid')
        if not feepaid:
            raise ValidationError('Please pay the fee First :)')
        return feepaid

    def clean_participants(self):
        participants_data = self.cleaned_data.get('participants')
        event = self.cleaned_data.get('event')
        participants =[]

        for pd in participants_data.split(','):
            p = Candidate.objects.get(pk=pd)
            participants.append(p)
        if not (event.minParticipant <= len(participants) <= event.maxParticipant):
            raise ValidationError('Number of Participants exceeded :D')
        return participants

    def __init__(self, *args, **kwargs):
        super(EventRegistrationForm, self).__init__(*args, **kwargs)
        self.fields['event'].empty_label = ''
        # following line needed to refresh widget copy of choice list
        self.fields['event'].widget.choices =self.fields['event'].choices
class EventRegistrationForm(forms.ModelForm):
参与者=forms.CharField(widget=forms.TextInput(attrs={'autocomplete':'off','data role':'tagsinput'}),必需=True)
类元:
模型=事件注册
字段=['event'、'participants'、'teamName'、'feepad']
def清洁费(自付):
feepayed=self.cleanned\u data.get('feepayed')
如果未支付:
raise ValidationError('请先支付费用:)')
已付回程费
def clean_参与者(自我):
参与者数据=self.cleanned\u data.get('参与者')
event=self.cleaned_data.get('event'))
参与者=[]
对于参与者数据中的pd。拆分(','):
p=Candidate.objects.get(pk=pd)
参与者。追加(p)

如果不是(event.minParticipant,则可以通过m2m字段的列表。
我刚刚错过了表单。save_m2m()。

可以传递m2m字段的列表。 我刚刚错过了表单。保存