change: change order list serializer and views
This commit is contained in:
@@ -4,9 +4,24 @@ from core.apps.orders.models import Order
|
||||
|
||||
|
||||
class OrderListSerializer(serializers.ModelSerializer):
|
||||
location_to = serializers.SerializerMethodField(method_name='get_location_to')
|
||||
location_from = serializers.SerializerMethodField(method_name='get_location_from')
|
||||
|
||||
class Meta:
|
||||
model = Order
|
||||
fields = [
|
||||
'id', 'order_number', 'name', 'date', 'status', 'size', 'total_price', 'is_paid', 'location', 'location_to',
|
||||
'location_from'
|
||||
]
|
||||
|
||||
def get_location_to(self, obj):
|
||||
return {
|
||||
'id': obj.location_to.id,
|
||||
'name': obj.location_to.name
|
||||
}
|
||||
|
||||
def get_location_from(self, obj):
|
||||
return {
|
||||
'id': obj.location_from.id,
|
||||
'name': obj.location_from.name
|
||||
}
|
||||
@@ -6,7 +6,7 @@ from core.apps.orders import serializers, models
|
||||
|
||||
class OrderListApiView(generics.GenericAPIView):
|
||||
serializer_class = serializers.OrderListSerializer
|
||||
queryset = models.Order.objects.all()
|
||||
queryset = models.Order.objects.select_related('location_to', 'location_from')
|
||||
permission_classes = [permissions.IsAuthenticated]
|
||||
|
||||
def get(self, request):
|
||||
|
||||
Reference in New Issue
Block a user