我創建一個聊天應用程序,並有2場,收件人的姓名和身體, 我想疏通全身是沒有形式出現後清零接收者的姓名提交comment
場,我怎麼能做到這一點?如何在提交後只清除一個特定的表單域?
views.py
if request.method == 'POST':
form = userCommentForm(request.POST, request.FILES)
if form.is_valid():
form.save(client=request.user)
> clear comment field.
forms.py( 「工人」 字段是接收者的姓名。)
class userCommentForm(forms.Form):
worker = CommaSeparatedUserField(label=_(u"worker"), widget=forms.TextInput(attrs={'readonly': 'readonly'}))
comment = forms.CharField(label=_(u"comment"), widget=forms.Textarea())
def save(self, client):
workers = self.cleaned_data['worker']
comment = self.cleaned_data['comment']
message_list = []
for worker in workers:
msg = userComment(client=client, worker=worker, comment=comment,)
if None is not None:
msg.parent_msg = None
None.save()
msg.save()
message_list.append(msg)
return message_list
form.save(client=request.user)
有什麼建議?
你是什麼意思'清晰的身體領域? –
一旦形式submited,'comment'領域應清除 – Lindow