From a48c1ca07777fbe48c48a6d5846adb699e6c5f3f Mon Sep 17 00:00:00 2001 From: Mads Nylund Date: Tue, 19 Sep 2023 11:58:39 +0200 Subject: [PATCH] fixed circular import error in order serializer --- app/content/views/user.py | 4 +--- app/payment/serializers/order.py | 29 ++++++++++++++++++++--------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/content/views/user.py b/app/content/views/user.py index fa127fd8a..24b4cbd62 100644 --- a/app/content/views/user.py +++ b/app/content/views/user.py @@ -37,7 +37,6 @@ MembershipHistorySerializer, MembershipSerializer, ) -from app.payment.models import Order from app.payment.views import OrderListSerializer from app.util.export_user_data import export_user_data from app.util.utils import CaseInsensitiveBooleanQueryParam @@ -289,8 +288,7 @@ def get_user_events(self, request, *args, **kwargs): @action(detail=False, methods=["get"], url_path="me/payment_orders") def get_user_payment_orders(self, request, *args, **kwargs): - user = self.get_object() - payment_orders = Order.objects.filter(user=user) + payment_orders = request.user.orders.all() return self.paginate_response( data=payment_orders, serializer=OrderListSerializer, context={"request": request} ) diff --git a/app/payment/serializers/order.py b/app/payment/serializers/order.py index fc92742f6..a92369b2f 100644 --- a/app/payment/serializers/order.py +++ b/app/payment/serializers/order.py @@ -12,15 +12,6 @@ class Meta: fields = ("order_id", "status", "expire_date", "payment_link", "event", "user") -class OrderListSerializer(BaseModelSerializer): - # TODO: fix this circular import issue so that I can use the event serializer - # event = EventSerializer(read_only=True) - - class Meta: - model = Order - fields = ("status", "user", "event") - - class OrderUpdateCreateSerializer(BaseModelSerializer): user = DefaultUserSerializer(read_only=True) @@ -38,3 +29,23 @@ def create(self, validated_data): return Order.objects.create( user=user, expired_date=now() + paytime, **validated_data ) + + +class OrderEventListSerializer(BaseModelSerializer): + + class Meta: + model = Event + fields = ( + "title", + ) + +class OrderListSerializer(BaseModelSerializer): + event = OrderEventListSerializer(read_only=True) + + class Meta: + model = Order + fields = ( + "status", + "user", + "event" + ) \ No newline at end of file