Skip to content

Commit

Permalink
booking+quantity
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaniog committed Jun 15, 2024
1 parent 00496da commit 25b2b80
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/apps/amo/dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion backend/apps/booking/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",)
20 changes: 20 additions & 0 deletions backend/apps/booking/migrations/0011_booking_quantity.py
Original file line number Diff line number Diff line change
@@ -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,
),
]
1 change: 1 addition & 0 deletions backend/apps/booking/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)])
2 changes: 1 addition & 1 deletion backend/apps/booking/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
14 changes: 7 additions & 7 deletions backend/apps/payments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])

0 comments on commit 25b2b80

Please sign in to comment.