mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-03-20 08:34:07 +01:00
30 lines
881 B
Python
30 lines
881 B
Python
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__"
|