ユーザーが選択した特定のスロット(時間、クラブ、日、裁判所が関連付けられている必要があります)について、「username」に保存されている値をクラスOpeningの「reservation」フィールドに保存するにはどうすればよいですか?
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)