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.core.cache import cache
|
||||||
from django.db.models.functions import Length
|
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.serializers import ModelSerializer
|
||||||
from rest_framework_recursive.fields import RecursiveField
|
from rest_framework_recursive.fields import RecursiveField
|
||||||
|
|
||||||
|
|
@ -26,6 +26,7 @@ from core.models import (
|
||||||
Vendor,
|
Vendor,
|
||||||
Wishlist,
|
Wishlist,
|
||||||
)
|
)
|
||||||
|
from core.serializers import AddressSerializer
|
||||||
from core.serializers.simple import CategorySimpleSerializer, ProductSimpleSerializer
|
from core.serializers.simple import CategorySimpleSerializer, ProductSimpleSerializer
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
@ -386,6 +387,9 @@ class WishlistDetailSerializer(ModelSerializer):
|
||||||
|
|
||||||
class OrderProductDetailSerializer(ModelSerializer):
|
class OrderProductDetailSerializer(ModelSerializer):
|
||||||
product = ProductDetailSerializer()
|
product = ProductDetailSerializer()
|
||||||
|
billing_address = AddressSerializer(read_only=True, required=False)
|
||||||
|
shipping_address = AddressSerializer(read_only=True, required=False)
|
||||||
|
attributes = JSONField(required=False)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = OrderProduct
|
model = OrderProduct
|
||||||
|
|
@ -396,6 +400,8 @@ class OrderProductDetailSerializer(ModelSerializer):
|
||||||
"buy_price",
|
"buy_price",
|
||||||
"comments",
|
"comments",
|
||||||
"notifications",
|
"notifications",
|
||||||
|
"billing_address",
|
||||||
|
"shipping_address",
|
||||||
"attributes",
|
"attributes",
|
||||||
"status",
|
"status",
|
||||||
"created",
|
"created",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
from contextlib import suppress
|
from contextlib import suppress
|
||||||
from typing import Optional
|
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.relations import PrimaryKeyRelatedField
|
||||||
from rest_framework.serializers import ModelSerializer
|
from rest_framework.serializers import ModelSerializer
|
||||||
|
|
||||||
|
|
@ -23,6 +23,7 @@ from core.models import (
|
||||||
Vendor,
|
Vendor,
|
||||||
Wishlist,
|
Wishlist,
|
||||||
)
|
)
|
||||||
|
from core.serializers import AddressSerializer
|
||||||
|
|
||||||
|
|
||||||
class AttributeGroupSimpleSerializer(ModelSerializer):
|
class AttributeGroupSimpleSerializer(ModelSerializer):
|
||||||
|
|
@ -287,12 +288,18 @@ class OrderSimpleSerializer(ModelSerializer):
|
||||||
user = PrimaryKeyRelatedField(read_only=True)
|
user = PrimaryKeyRelatedField(read_only=True)
|
||||||
promo_code = PromoCodeSimpleSerializer(read_only=True)
|
promo_code = PromoCodeSimpleSerializer(read_only=True)
|
||||||
order_products = OrderProductSimpleSerializer(many=True, 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:
|
class Meta:
|
||||||
model = Order
|
model = Order
|
||||||
fields = [
|
fields = [
|
||||||
"uuid",
|
"uuid",
|
||||||
"human_readable_id",
|
"human_readable_id",
|
||||||
|
"billing_address",
|
||||||
|
"shipping_address",
|
||||||
|
"attributes",
|
||||||
"status",
|
"status",
|
||||||
"user",
|
"user",
|
||||||
"promo_code",
|
"promo_code",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue