feat: add api

This commit is contained in:
Herculino Trotta
2024-10-09 22:25:22 -03:00
parent 5a2fa2bb2d
commit d66ca1e8af
13 changed files with 243 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
from rest_framework import serializers
from apps.currencies.models import Currency, ExchangeRate
class CurrencySerializer(serializers.ModelSerializer):
class Meta:
model = Currency
fields = "__all__"
class ExchangeRateSerializer(serializers.ModelSerializer):
# For read operations (GET)
from_currency = CurrencySerializer(read_only=True)
# For write operations (POST, PUT, PATCH)
from_currency_id = serializers.PrimaryKeyRelatedField(
queryset=Currency.objects.all(), source="from_currency", write_only=True
)
to_currency = CurrencySerializer(read_only=True)
# For write operations (POST, PUT, PATCH)
to_currency_id = serializers.PrimaryKeyRelatedField(
queryset=Currency.objects.all(), source="from_currency", write_only=True
)
class Meta:
model = ExchangeRate
fields = "__all__"