From 2d851097f95dae7ee8385105e8adce875344ef44 Mon Sep 17 00:00:00 2001 From: ARYAN-NIKNEZHAD Date: Wed, 30 Oct 2024 13:49:06 +0330 Subject: [PATCH] fix(api): Add lookup_field CategoryViewSet and add serializer source field for handel customer name Closes(#30) --- sage_invoice/api/serializers/invoice.py | 3 ++- sage_invoice/api/views/category.py | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/sage_invoice/api/serializers/invoice.py b/sage_invoice/api/serializers/invoice.py index f674cfd..da0593a 100644 --- a/sage_invoice/api/serializers/invoice.py +++ b/sage_invoice/api/serializers/invoice.py @@ -41,6 +41,7 @@ class InvoiceSerializer(serializers.HyperlinkedModelSerializer): child=serializers.DictField(child=serializers.CharField()), required=False ) category = CategorySerializer(read_only=True) + customer_name = serializers.CharField(source="customer.name") items = ItemSerializer(many=True, read_only=True) columns = ColumnSerializer(many=True, read_only=True) expense = ExpenseSerializer(read_only=True) @@ -70,7 +71,7 @@ class Meta: ] extra_kwargs = { "url": {"lookup_field": "slug"}, - "categories": {"lookup_field": "slug"}, + "category": {"lookup_field": "slug"}, "items": {"lookup_field": "id"}, "columns": {"lookup_field": "id"}, "expense": {"lookup_field": "id"}, diff --git a/sage_invoice/api/views/category.py b/sage_invoice/api/views/category.py index 8dc1411..31f4b49 100644 --- a/sage_invoice/api/views/category.py +++ b/sage_invoice/api/views/category.py @@ -9,6 +9,7 @@ class CategoryViewSet(ErrorHandlingMixin, viewsets.ModelViewSet): queryset = Category.objects.all() serializer_class = CategorySerializer + lookup_field = "slug" versioning_class = HeaderVersioning