55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
from rest_framework import serializers
|
|
|
|
from rest_framework import serializers
|
|
from .models import Product, Carrier, Order
|
|
|
|
from ...commerce.serializers import ProductSerializer, CarrierSerializer
|
|
|
|
|
|
class OrderSerializer(serializers.ModelSerializer):
|
|
product = ProductSerializer(read_only=True)
|
|
product_id = serializers.PrimaryKeyRelatedField(
|
|
queryset=Product.objects.all(), source="product", write_only=True
|
|
)
|
|
carrier = CarrierSerializer(read_only=True)
|
|
carrier_id = serializers.PrimaryKeyRelatedField(
|
|
queryset=Carrier.objects.all(), source="carrier", write_only=True
|
|
)
|
|
|
|
class Meta:
|
|
model = Order
|
|
fields = [
|
|
"id",
|
|
"product", "product_id",
|
|
"carrier", "carrier_id",
|
|
"quantity",
|
|
"total_price",
|
|
"status",
|
|
"stripe_session_id",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
read_only_fields = ("total_price", "status", "stripe_session_id", "created_at", "updated_at")
|
|
|
|
queryset=Product.objects.all(), source="product", write_only=True
|
|
|
|
carrier = CarrierSerializer(read_only=True)
|
|
carrier_id = serializers.PrimaryKeyRelatedField(
|
|
queryset=Carrier.objects.all(), source="carrier", write_only=True
|
|
)
|
|
|
|
class Meta:
|
|
model = Order
|
|
fields = [
|
|
"id",
|
|
"product", "product_id",
|
|
"carrier", "carrier_id",
|
|
"quantity",
|
|
"total_price",
|
|
"status",
|
|
"stripe_session_id",
|
|
"created_at",
|
|
"updated_at",
|
|
]
|
|
read_only_fields = ("total_price", "status", "stripe_session_id", "created_at", "updated_at")
|