Features: Add fields for addresses and attributes in Order's serializers.
Extra: 1) Minor code improvements.
This commit is contained in:
parent
e0eaf55d73
commit
af61a7ddff
2 changed files with 15 additions and 2 deletions
|
|
@ -4,7 +4,7 @@ from typing import Optional
|
|||
|
||||
from django.core.cache import cache
|
||||
from django.db.models.functions import Length
|
||||
from rest_framework.fields import SerializerMethodField
|
||||
from rest_framework.fields import JSONField, SerializerMethodField
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
from rest_framework_recursive.fields import RecursiveField
|
||||
|
||||
|
|
@ -26,6 +26,7 @@ from core.models import (
|
|||
Vendor,
|
||||
Wishlist,
|
||||
)
|
||||
from core.serializers import AddressSerializer
|
||||
from core.serializers.simple import CategorySimpleSerializer, ProductSimpleSerializer
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
|
@ -386,6 +387,9 @@ class WishlistDetailSerializer(ModelSerializer):
|
|||
|
||||
class OrderProductDetailSerializer(ModelSerializer):
|
||||
product = ProductDetailSerializer()
|
||||
billing_address = AddressSerializer(read_only=True, required=False)
|
||||
shipping_address = AddressSerializer(read_only=True, required=False)
|
||||
attributes = JSONField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = OrderProduct
|
||||
|
|
@ -396,6 +400,8 @@ class OrderProductDetailSerializer(ModelSerializer):
|
|||
"buy_price",
|
||||
"comments",
|
||||
"notifications",
|
||||
"billing_address",
|
||||
"shipping_address",
|
||||
"attributes",
|
||||
"status",
|
||||
"created",
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
from contextlib import suppress
|
||||
from typing import Optional
|
||||
|
||||
from rest_framework.fields import SerializerMethodField
|
||||
from rest_framework.fields import JSONField, SerializerMethodField
|
||||
from rest_framework.relations import PrimaryKeyRelatedField
|
||||
from rest_framework.serializers import ModelSerializer
|
||||
|
||||
|
|
@ -23,6 +23,7 @@ from core.models import (
|
|||
Vendor,
|
||||
Wishlist,
|
||||
)
|
||||
from core.serializers import AddressSerializer
|
||||
|
||||
|
||||
class AttributeGroupSimpleSerializer(ModelSerializer):
|
||||
|
|
@ -287,12 +288,18 @@ class OrderSimpleSerializer(ModelSerializer):
|
|||
user = PrimaryKeyRelatedField(read_only=True)
|
||||
promo_code = PromoCodeSimpleSerializer(read_only=True)
|
||||
order_products = OrderProductSimpleSerializer(many=True, read_only=True)
|
||||
billing_address = AddressSerializer(read_only=True, required=False)
|
||||
shipping_address = AddressSerializer(read_only=True, required=False)
|
||||
attributes = JSONField(required=False)
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = [
|
||||
"uuid",
|
||||
"human_readable_id",
|
||||
"billing_address",
|
||||
"shipping_address",
|
||||
"attributes",
|
||||
"status",
|
||||
"user",
|
||||
"promo_code",
|
||||
|
|
|
|||
Loading…
Reference in a new issue