mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-04-25 10:08:36 +02:00
feat: add api
This commit is contained in:
29
app/apps/api/serializers/currencies.py
Normal file
29
app/apps/api/serializers/currencies.py
Normal 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__"
|
||||
Reference in New Issue
Block a user