我有形式的列表視圖:保存後的數據
class MatchsView(ListView):
model = Match2x1
template_name = 'matchs.html'
和模板渲染這樣的:
{% for match in object_list %}
<form action="/apostar/" method="post">{% csrf_token %}
<p><input type="radio" name="{{match.id}}" value="{{match.team_a}}">{{match.team_a}}</input></p>
<input type="submit" value="Apostar"></input>
</form>
{% endfor %}
,你可以看到每種形式都有兩個領域,我需要在DB中保存用戶選擇的值,用FormView很容易,但是因爲這次是一個ListView,我有點損失從表單中保存在DB中,我知道我必須創建一個處理表單的視圖,但真的我不知道如何創建處理每個窗體的發佈數據的視圖。例如,讓我說我需要保存一個名爲FormsMatchs
的模型中的發佈數據,我該怎麼做?
有了這個,我是想:
class FormView(FormView):
form_class = FormMatch
success_url = '/'
template_name = 'matchs.html'
def post(self, request, *args, **kwargs):
hola = Country.objects.create(name=request.POST)
但保存此:
<QueryDict: {u'csrfmiddlewaretoken': [u'tCIQuGlSXKJL0R5eo9R5w09ldeBt7zNW'], u'5': [u'River']}>
你可以在這裏添加你的表格嗎? – 2015-03-25 00:03:59