Skip to content

Commit

Permalink
Merge pull request #32 from ARYAN-NIKNEZHAD/bug/invoice-api
Browse files Browse the repository at this point in the history
fix(api): Add lookup_field CategoryViewSet and add serializer source field for handel customer name
  • Loading branch information
sepehr-akbarzadeh authored Dec 5, 2024
2 parents 0bcae33 + 2d85109 commit 7aeafe5
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
3 changes: 2 additions & 1 deletion sage_invoice/api/serializers/invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"},
Expand Down
1 change: 1 addition & 0 deletions sage_invoice/api/views/category.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class CategoryViewSet(ErrorHandlingMixin, viewsets.ModelViewSet):
queryset = Category.objects.all()
serializer_class = CategorySerializer
lookup_field = "slug"

versioning_class = HeaderVersioning

Expand Down

0 comments on commit 7aeafe5

Please sign in to comment.