make django models for a movie management system for different movie that can be seen…
- User
make django models for a movie management system for different movie that can be seen many times and a show table that consist of time, uuid and movie foreign key as well as keep track of the seat matrix. each person can only maximum book 2 tickets in a month and when the month is over ticket count should be zero.
- Assistant
Here are the Django models for the described movie management system:
from django.db import models from django.contrib.auth.models import User class Movie(models.Model): title = models.CharField(max_length=255) description = models.TextField() poster = models.ImageField(upload_to='movie_posters/') available = models.BooleanField(default=True) def __str__(self): return self.title class Show(models.Model): movie = models.ForeignKey(Movie, on_delete=models.CASCADE) time = models.DateTimeField() uuid = models.CharField(max_length=32, unique=True) seats = models.JSONField(default=dict) def __str__(self): return f"{self.movie.title} ({self.time.strftime('%Y-%m-%d %H:%M')})" class Booking(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) show = models.ForeignKey(Show, on_delete=models.CASCADE) seats = models.JSONField(default=list) def __str__(self): return f"{self.user.username} - {self.show}" def save(self, *args, **kwargs): # Check if user has already booked 2 tickets this month bookings_this_month = Booking.objects.filter(user=self.user, show__time__month=self.show.time.month) if len(bookings_this_month) >= 2: raise ValueError("You can only book 2 tickets per month.") super().save(*args, **kwargs) - User
add a seat matrix that will track all the selected seats as welll
- Assistant
- User
make seats a different table that has show as a one to one field.
- Assistant