diff --git a/backend/apps/amo/dto.py b/backend/apps/amo/dto.py index 33c3662..af00922 100644 --- a/backend/apps/amo/dto.py +++ b/backend/apps/amo/dto.py @@ -104,7 +104,7 @@ def group_bookings_by_place_event_time(order): print(bookings) for booking in bookings: key = (booking.event.place.name, booking.event.name, booking.time) - grouped_data[key]['types'][booking.ticket.get_type_display()] += 1 + grouped_data[key]['types'][booking.ticket.get_type_display()] = booking.quantity grouped_data[key]['price'] += int(booking.ticket.price) return [ diff --git a/backend/apps/booking/admin.py b/backend/apps/booking/admin.py index 5600709..ec6f8ba 100644 --- a/backend/apps/booking/admin.py +++ b/backend/apps/booking/admin.py @@ -33,7 +33,7 @@ class CartTicketAdmin(admin.ModelAdmin): @admin.register(Booking) class BookingAdmin(admin.ModelAdmin): - list_display = ("id", "event", "ticket", "time", "cart") + list_display = ("id", "event", "ticket", "time", "cart", "quantity") list_filter = ("time",) search_fields = ("id",) readonly_fields = ("id",) diff --git a/backend/apps/booking/migrations/0011_booking_quantity.py b/backend/apps/booking/migrations/0011_booking_quantity.py new file mode 100644 index 0000000..2a11cf0 --- /dev/null +++ b/backend/apps/booking/migrations/0011_booking_quantity.py @@ -0,0 +1,20 @@ +# Generated by Django 5.0.6 on 2024-06-15 18:17 + +import django.core.validators +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('booking', '0010_booking_visited'), + ] + + operations = [ + migrations.AddField( + model_name='booking', + name='quantity', + field=models.IntegerField(default=1, validators=[django.core.validators.MinValueValidator(0)]), + preserve_default=False, + ), + ] diff --git a/backend/apps/booking/models.py b/backend/apps/booking/models.py index 5f81285..e99a973 100644 --- a/backend/apps/booking/models.py +++ b/backend/apps/booking/models.py @@ -43,3 +43,4 @@ class Booking(models.Model): time = models.DateTimeField() cart = models.ForeignKey(Cart, on_delete=models.CASCADE) visited = models.BooleanField(default=False) + quantity = models.IntegerField(validators=[MinValueValidator(0)]) diff --git a/backend/apps/booking/serializers.py b/backend/apps/booking/serializers.py index 1ae4e90..ec44c4e 100644 --- a/backend/apps/booking/serializers.py +++ b/backend/apps/booking/serializers.py @@ -73,4 +73,4 @@ class Meta: class BookingSerializer(serializers.ModelSerializer): class Meta: model = Booking - fields = ("id", "event", "ticket", "time", "visited") + fields = ("id", "event", "ticket", "time", "visited", "quantity") diff --git a/backend/apps/payments/models.py b/backend/apps/payments/models.py index 2cbacec..c1a8925 100644 --- a/backend/apps/payments/models.py +++ b/backend/apps/payments/models.py @@ -33,11 +33,11 @@ class Order(models.Model): def create_bookings(sender, instance, **kwargs): print(instance.cart.tickets.all()) for t in instance.cart.tickets.all(): - for _ in range(t.quantity): - Booking.objects.create( - event=t.event, - ticket=t.ticket, - time=t.time, - cart=t.cart - ) + Booking.objects.create( + event=t.event, + ticket=t.ticket, + time=t.time, + cart=t.cart, + quantity=t.quantity + ) post_orders([instance])