Would and if yes an example of a moneyed / django-money be useful to be added to the documentation somewhere? It is a non-trivial implementation with a few pitfalls including optimizing DB queries. Follows the Shopify GQL API.
from decimal import Decimal
from enum import Enum
from moneyed import CURRENCIES_BY_ISO
import strawberry
from decimal import Decimal
from strawberry import relay
import strawberry_django
CurrencyCode = strawberry.enum(
Enum("CurrencyCode", {i.code: i.code for i in CURRENCIES_BY_ISO.values()})
)
@strawberry.type(name="Money")
class MoneyType:
amount: Decimal
currency_code: CurrencyCode
@strawberry_django.type(MyDjangoModel)
class MyGQLNode(relay.Node):
@strawberry_django.field(only=["plan_price", "plan_price_currency"])
def plan_price(self, root: FSSubscription) -> MoneyType:
return MoneyType(
amount=root.plan_price.amount, currency_code=root.plan_price_currency
)
from moneyed import EUR, Money
from django.db import models
from djmoney.models.fields import MoneyField
class MyDjangoModel(models.Model):
plan_price = MoneyField(
max_digits=19,
decimal_places=4,
default_currency=EUR,
help_text="The current price of the plan",
)
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too