Skip to content

Commit 6ebd9c6

Browse files
feat: return human-readable status text in Order API
- Replace ReadOnlyField with SerializerMethodField for status - Add get_status method to return display text (e.g., Completed instead of CO) - Improve API usability with meaningful status labels - Make order status more user-friendly for frontend consumption
1 parent ac6850b commit 6ebd9c6

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

orders/serializers.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ class Meta:
3434
decimal_places=2,
3535
read_only=True
3636
)
37-
status = serializers.ChoiceField(choices=Order.Status.choices)
37+
status = serializers.SerializerMethodField()
3838

3939
class Meta:
4040
model = Order
4141
fields = ['order_id', 'user', 'quantity', 'order_date', 'order_items', 'original_price', 'total_price',
4242
'coupon', 'discount', 'status']
4343
read_only_fields = ['user', 'order_date']
4444

45+
def get_status(self, obj):
46+
return obj.get_status_display()
47+
4548
def update(self, instance, validated_data):
4649
# Check if status is in the incoming data and the user is allowed to update it
4750
request = self.context.get('request')

0 commit comments

Comments
 (0)