доделал страницу выбора мест, изменил базу

This commit is contained in:
Андрей Дувакин 2024-04-20 22:49:43 +05:00
parent b116bc18b9
commit 72e025bb34
7 changed files with 172 additions and 16 deletions

View File

@ -7,7 +7,7 @@
border-radius: 3vw;
display: flex;
width: 46%;
max-height: 50vw;
max-height: 50vw !important ;
overflow-x: scroll;
overflow-y: scroll;
flex-direction: column;
@ -15,6 +15,7 @@
}
.table_card {
margin: 3vw;
margin-top: 1.5vw;
}
.seat_checkbox {
display: none;
@ -34,8 +35,9 @@
text-align: center;
}
.buy_btn {
float: bottom;
margin-top: 1.5vw;
margin-top: 2vw;
margin-left: 2vw;
margin-right: 2vw;
}
.ticket_film_image {
object-fit: cover;
@ -105,4 +107,14 @@
.film_info_description::-webkit-scrollbar-thumb {
background-color: #eaeaea;
border-radius: 5vw;
}
.horizontal_line {
margin-left: 2vw;
margin-right: 2vw;
border-top: 10px solid;
}
.display_title {
width: 100%;
text-align: center;
font-size: 1.2vw;
}

View File

@ -1,4 +1,4 @@
document.querySelectorAll('.seat_checkbox').forEach(function(checkbox) {
document.querySelectorAll('.seat_checkbox').forEach(function(checkbox) {
checkbox.addEventListener('change', function() {
var filmSession = checkbox.closest('.film_session');
if (checkbox.checked) {
@ -7,4 +7,31 @@
filmSession.classList.remove('selected');
}
});
});
});
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('.seats_card');
const checkboxes = form.querySelectorAll('.seat_checkbox');
const buyButton = form.querySelector('.buy_btn');
function checkSelected() {
let atLeastOneSelected = false;
checkboxes.forEach(function(checkbox) {
if (checkbox.checked) {
atLeastOneSelected = true;
}
});
if (atLeastOneSelected) {
buyButton.style.display = 'block';
} else {
buyButton.style.display = 'none';
}
}
checkboxes.forEach(function(checkbox) {
checkbox.addEventListener('change', checkSelected);
});
checkSelected();
});

View File

@ -23,7 +23,10 @@
</div>
</div>
<form class="seats_card" method="post" style="height: {{ height }}vw;">
<button type="submit" class="btn btn-primary buy_btn">Купить билет</button>
{% csrf_token %}
<hr class="horizontal_line">
<p class="display_title">Экран</p>
<table class="table_card">
<tbody>
{% for row in session.auditorium.rows.all %}
@ -43,6 +46,5 @@
</tbody>
</table>
</form>
<button type="submit" class="btn btn-primary buy_btn">Купить билет</button>
<script src="{% static 'js/timetable/session.js' %}"></script>
{% endblock %}

View File

@ -0,0 +1,84 @@
# Generated by Django 4.2 on 2024-04-20 17:48
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
("timetable", "0006_remove_auditorium_row_count"),
("users", "0003_remove_profile_genres_profile_genres"),
("tickets", "0005_alter_ticket_options_alter_ticket_table"),
]
operations = [
migrations.RemoveField(
model_name="ticket",
name="profile",
),
migrations.RemoveField(
model_name="ticket",
name="session",
),
migrations.AlterModelTable(
name="ticket",
table="tickets_tickets",
),
migrations.CreateModel(
name="Order",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
(
"datetime_order",
models.DateField(
help_text="Дата и время оформления заказа",
verbose_name="Дата и время оформления заказа",
),
),
(
"profile",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
related_query_name="orders",
to="users.profile",
),
),
(
"session",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="orders",
related_query_name="orders",
to="timetable.filmsession",
),
),
],
options={
"verbose_name": "Заказ",
"verbose_name_plural": "Заказы",
"db_table": "tickets_orders",
},
),
migrations.AddField(
model_name="ticket",
name="order",
field=models.ForeignKey(
default="",
on_delete=django.db.models.deletion.CASCADE,
related_name="tickets",
related_query_name="tickets",
to="tickets.order",
),
preserve_default=False,
),
]

View File

@ -1,21 +1,40 @@
from django.db.models import ForeignKey, CASCADE, Model, IntegerField
from django.db.models import ForeignKey, CASCADE, Model, IntegerField, DateField
from django.core.validators import MinValueValidator
from timetable.models import FilmSession
from users.models import Profile
class Ticket(Model):
class Order(Model):
session = ForeignKey(
FilmSession,
on_delete=CASCADE,
related_name='tickets',
related_query_name='tickets',
related_name='orders',
related_query_name='orders',
)
profile = ForeignKey(
Profile,
on_delete=CASCADE,
related_name='orders',
related_query_name='orders',
)
datetime_order = DateField(
verbose_name='Дата и время оформления заказа',
help_text='Дата и время оформления заказа',
)
class Meta:
db_table = 'tickets_orders'
verbose_name = 'Заказ'
verbose_name_plural = 'Заказы'
class Ticket(Model):
order = ForeignKey(
Order,
on_delete=CASCADE,
related_name='tickets',
related_query_name='tickets',
)
@ -35,6 +54,6 @@ class Ticket(Model):
)
class Meta:
db_table = 'tickets_ticket'
db_table = 'tickets_tickets'
verbose_name = 'Билет'
verbose_name_plural = 'Билеты'

View File

@ -0,0 +1,17 @@
# Generated by Django 4.2 on 2024-04-20 16:49
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
("timetable", "0005_filmsession_end_datetime"),
]
operations = [
migrations.RemoveField(
model_name="auditorium",
name="row_count",
),
]

View File

@ -48,10 +48,6 @@ def session_view(request, sess_id):
id=sess_id,
)
height = round(session.auditorium.rows.count() * 4 + 7)
row_with_most_seats = Row.objects.filter(auditorium=session.auditorium).only('column_count').annotate(
max_seats=Max('column_count')
).order_by('-max_seats').first()
width = round(row_with_most_seats.column_count * 4 + 3)
if request.method == 'POST':
form = SeatSelectionForm(request.POST, auditorium=session.auditorium)
@ -65,7 +61,6 @@ def session_view(request, sess_id):
'session': session,
'height': height,
'form': form,
'width': width
}
template = 'timetable/session.html'
return render(request, template, context)