do not run forms code during migration

database does not exist yet
This commit is contained in:
2021-05-11 09:53:52 +02:00
parent 5ac5f1c2d7
commit 68efd595b7
+3 -1
View File
@@ -1,4 +1,5 @@
from django import forms
import sys
import datetime
from apps.transactions.models import Transaction
from apps.rates.models import ExchangeRate
@@ -16,6 +17,8 @@ class TransactionForm(forms.ModelForm):
model = Transaction
fields = "__all__"
# do not run this code in initial migration, because the database has not been built yet
if not "migrate" in sys.argv:
exchangerates = ExchangeRate.objects.filter(datetime_valid__gt = datetime.datetime.today() - datetime.timedelta(days=7))
crypto_currencies = [(x, x) for x in sorted({ex.crypto_currency for ex in exchangerates})]
fiat_currencies = [(x, x) for x in sorted({ex.fiat_currency for ex in exchangerates})]
@@ -25,7 +28,6 @@ class TransactionForm(forms.ModelForm):
'crypto_currency': forms.Select(choices = crypto_currencies),
}
class ImportForm(forms.Form):
api_key = forms.CharField(label='API Key', widget=forms.PasswordInput, max_length=100)
api_secret = forms.CharField(label='API Secret', widget=forms.PasswordInput, max_length=100)