Answer the question
In order to leave comments, you need to log in
How do I fix the form handler so that it works?
It is not possible to implement the entry posting form next to the entries that already exist.
The form:
class CinemaForm(forms.Form):
th_name = forms.CharField(label='Название кинотеатра')
time = forms.DateTimeField(label='Сеансы')
address = forms.CharField(label='Адрес кинотеатра')
cn_name = forms.CharField(label='Название фильма')
Модель:
class Cinema(models.Model):
theater_name = models.TextField(max_length = 35, blank=False)
theater_address = models.TextField(max_length=35, blank=False)
cinema_timetable = models.DateTimeField(blank=False)
cinema_name = models.TextField(max_length=35, blank=False)
def cinema(request):
all_cinema = Cinema.objects.all()
cinema_form = CinemaForm
if request.POST:
newpost_form = CinemaForm(request.POST)
if newpost_form.is_valid():
newpost_form.save()
return redirect("/")
return render_to_response("theatername.html", {"cinema": all_cinema, "form": cinema_form})
{% block theater %}
{% for theater in cinema %}
<table class="table table-bordered">
<thead>
<tr>
<th>Адрес</th>
<th>Название кинотеатра</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ theater.theater_address }}</td>
<td>{{ theater.theater_name }}</td>
</tr>
</tbody>
</table>
<br>
{% endfor %}
<form action="/" method="post">
{% csrf_token %}
{{ form.as_ul }}
<input class="btn btn-success" type="submit" value="Добавить">
{% endblock %}
{% block seance %}
{% for theater in cinema %}
<table class="table table-bordered">
<thead>
<tr>
<th>Название кинотеатра</th>
<th>Расписание</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ theater.theater_name }}</td>
<td>{{ theater.cinema_timetable }} - {{ theater.cinema_name }}</td>
</tr>
</tbody>
</table>
<br>
{% endfor %}
<form action="/" method="post">
{{ form.as_ul }}
<input class="btn btn-success" type="submit" value="Добавить">
{% endblock %}
Answer the question
In order to leave comments, you need to log in
There is no such method (save) for the form. You need to use ModelForm.
class CinemaForm(forms.ModelForm):
class Meta:
model = Cinema
fields = ('theater_name', 'theater_address', 'cinema_timetable', 'cinema_name')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question