mirror of
https://github.com/eitchtee/WYGIWYH.git
synced 2026-11-13 12:23:44 +01:00
Restore asset classes before accounts and take a second pass over accounts once categories, tags and entities exist, so their links survive a restore into a fresh install.
50 lines
1.5 KiB
Python
50 lines
1.5 KiB
Python
from import_export import fields, resources, widgets
|
|
|
|
from apps.accounts.models import Account, AccountGroup, InvestmentClass
|
|
from apps.export_app.widgets.foreign_key import AutoCreateForeignKeyWidget
|
|
from apps.currencies.models import Currency
|
|
|
|
|
|
class InvestmentClassResource(resources.ModelResource):
|
|
class Meta:
|
|
model = InvestmentClass
|
|
|
|
def get_queryset(self):
|
|
return InvestmentClass.all_objects.all()
|
|
|
|
|
|
class AllClassesWidget(widgets.ForeignKeyWidget):
|
|
# By id, across owners: a shared account may carry another user's class
|
|
def get_queryset(self, value, row, *args, **kwargs):
|
|
return InvestmentClass.all_objects.all()
|
|
|
|
|
|
class AccountResource(resources.ModelResource):
|
|
group = fields.Field(
|
|
attribute="group",
|
|
column_name="group",
|
|
widget=AutoCreateForeignKeyWidget(AccountGroup, "name"),
|
|
)
|
|
currency = fields.Field(
|
|
attribute="currency",
|
|
column_name="currency",
|
|
widget=widgets.ForeignKeyWidget(Currency, "name"),
|
|
)
|
|
exchange_currency = fields.Field(
|
|
attribute="exchange_currency",
|
|
column_name="exchange_currency",
|
|
widget=widgets.ForeignKeyWidget(Currency, "name"),
|
|
)
|
|
|
|
investment_class = fields.Field(
|
|
attribute="investment_class",
|
|
column_name="investment_class",
|
|
widget=AllClassesWidget(InvestmentClass),
|
|
)
|
|
|
|
class Meta:
|
|
model = Account
|
|
|
|
def get_queryset(self):
|
|
return Account.all_objects.all()
|