Skip to content

Instantly share code, notes, and snippets.

@aprilsnow7870
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aprilsnow7870/cb4087b1ead7b3e8d96d to your computer and use it in GitHub Desktop.
Save aprilsnow7870/cb4087b1ead7b3e8d96d to your computer and use it in GitHub Desktop.
#Views:
from django.shortcuts import render_to_response, redirect
from django.core.context_processors import csrf
from django.template import RequestContext
# Create your views here.
from theater.models import Cinema
from theater.models import CinemaForm
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})
#Template:
{% extends 'main.html' %}
{% load staticfiles %}
{% 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 method="post">
{% csrf_token %}
{{ form.as_ul }}
<input class="btn btn-success" type="submit" value="Добавить">
</form>
{% 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 %}
{% endblock %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment