Files
WYGIWYH/app/apps/export_app/resources/currencies.py
Herculino Trotta 069f1b450c feat: export (WIP)
2025-02-19 08:51:33 -03:00

47 lines
1.4 KiB
Python

from import_export import fields, resources, widgets
from apps.currencies.models import Currency, ExchangeRate, ExchangeRateService
class CurrencyResource(resources.ModelResource):
exchange_currency = fields.Field(
attribute="exchange_currency",
column_name="exchange_currency",
widget=widgets.ForeignKeyWidget("currencies.Currency", "name"),
)
class Meta:
model = Currency
class ExchangeRateResource(resources.ModelResource):
from_currency = fields.Field(
attribute="from_currency",
column_name="from_currency",
widget=widgets.ForeignKeyWidget("currencies.Currency", "name"),
)
to_currency = fields.Field(
attribute="to_currency",
column_name="to_currency",
widget=widgets.ForeignKeyWidget("currencies.Currency", "name"),
)
class Meta:
model = ExchangeRate
class ExchangeRateServiceResource(resources.ModelResource):
target_currencies = fields.Field(
attribute="target_currencies",
column_name="target_currencies",
widget=widgets.ManyToManyWidget("currencies.Currency", field="name"),
)
target_accounts = fields.Field(
attribute="target_accounts",
column_name="target_accounts",
widget=widgets.ForeignKeyWidget("accounts.Account", field="name"),
)
class Meta:
model = ExchangeRateService