对于用户选择的给定插槽(应该有时间、俱乐部、日期和球场),我如何将存储在“用户名”中的值保存到“开放”类的“预订”字段中?
def vote(request, club_id):
if 'username' in request.POST and request.POST['username'] and 'slot' in request.POST and request.POST['slot']:
username = request.POST['username']
slot = request.POST['slot']
#save the value stored in "username" to the "reservation" field in class Opening with the other associated data (club, time, day, court)
return HttpResponseRedirect('reserve/templates/booked.html',{'username':username, 'slot':slot})
else:
return render_to_response('reserve/templates/vote.html', {'error': True})
Avail_times.html:
<form action="/clubs/{{ club.id }}/vote/" method="post">
{% csrf_token %}
{{ today }}<br>
{% for slot in open_slots %}
<input type="checkbox" name="slot" id="slot{{ forloop.counter }}" value="{{ slot.id }}" />
<label for="slot{{ forloop.counter }}">{{ slot.slot }} on Court {{slot.court}}</label><br />
{% endfor %}
<br>
{{ tomorrow }}<br>
{% for slot in tom_open_slots %}
<input type="checkbox" name="slot" id="slot{{ forloop.counter }}" value="{{ slot.id }}" />
<label for="slot{{ forloop.counter }}">{{ slot.slot }} on Court {{slot.court}}</label><br />
{% endfor %}
<input type="text" name="username" />
<input type="submit" value="Reserve" />
模型:
from django.db import models
import datetime
class Club(models.Model):
establishment = models.CharField(max_length=200)
address = models.CharField(max_length=200)
def __unicode__(self):
return self.establishment
class Court(models.Model):
club = models.ForeignKey(Club)
day = models.ForeignKey(Day)
court = models.IntegerField(max_length=200)
def __unicode__(self):
return unicode(self.court)
class Opening(models.Model):
club = models.ForeignKey(Club)
day = models.DateField('date')
court = models.ForeignKey(Court)
slot = models.TimeField('slot')
reservation = models.CharField(max_length=200)
def __unicode__(self):
return unicode(self.slot)