Refactored order creation logic to use new serializers and transaction handling, improving validation and modularity. Introduced admin and public endpoints for shop configuration with sensitive fields protected. Enhanced Zásilkovna (Packeta) integration, including packet widget template, new API fields, and improved error handling. Added django-silk for profiling, updated requirements and settings, and improved frontend Orval config for API client generation.
55 lines
985 B
Python
55 lines
985 B
Python
from rest_framework import serializers
|
|
|
|
from .models import ZasilkovnaPacket, ZasilkovnaShipment
|
|
|
|
|
|
class ZasilkovnaPacketSerializer(serializers.ModelSerializer):
|
|
class Meta:
|
|
model = ZasilkovnaPacket
|
|
fields = [
|
|
"id",
|
|
"created_at",
|
|
"packet_id",
|
|
"barcode",
|
|
"state",
|
|
"weight",
|
|
"return_routing",
|
|
]
|
|
read_only_fields = [
|
|
"id",
|
|
"created_at",
|
|
"barcode",
|
|
"state",
|
|
"weight",
|
|
"return_routing",
|
|
]
|
|
|
|
|
|
#Just for tracking URL of packet
|
|
class TrackingURLSerializer(serializers.Serializer):
|
|
barcode = serializers.CharField(read_only=True)
|
|
tracking_url = serializers.URLField(read_only=True)
|
|
|
|
|
|
|
|
# -- SHIPMENT --
|
|
|
|
class ZasilkovnaShipmentSerializer(serializers.ModelSerializer):
|
|
packets = serializers.PrimaryKeyRelatedField(many=True)
|
|
|
|
class Meta:
|
|
model = ZasilkovnaShipment
|
|
fields = [
|
|
"id",
|
|
"created_at",
|
|
"shipment_id",
|
|
"barcode",
|
|
"packets",
|
|
]
|
|
read_only_fields = [
|
|
"id",
|
|
"created_at",
|
|
"shipment_id",
|
|
"barcode",
|
|
]
|