Skip to content

Commit

Permalink
fixed circular import error in order serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
MadsNyl committed Sep 19, 2023
1 parent f974530 commit a48c1ca
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
4 changes: 1 addition & 3 deletions app/content/views/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}
)
Expand Down
29 changes: 20 additions & 9 deletions app/payment/serializers/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"
)

0 comments on commit a48c1ca

Please sign in to comment.