use currencies from rates for select on add and edit views.
fix edit template to work with form directly fixes #2
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
from django import forms
|
||||
import datetime
|
||||
from apps.transactions.models import Transaction
|
||||
from apps.rates.models import ExchangeRate
|
||||
#from datetimepicker.widgets import DateTimePicker
|
||||
#from django.contrib.admin.widgets import AdminDateWidget
|
||||
|
||||
@@ -12,3 +14,12 @@ class TransactionForm(forms.ModelForm):
|
||||
# https://stackoverflow.com/a/52702275/1632368
|
||||
#date_valid = forms.DateField(widget=AdminDateWidget())
|
||||
|
||||
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})]
|
||||
|
||||
widgets = {
|
||||
'fiat_currency': forms.Select(choices = fiat_currencies),
|
||||
'crypto_currency': forms.Select(choices = crypto_currencies),
|
||||
}
|
||||
|
||||
|
||||
@@ -31,49 +31,49 @@
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Crypto Currency:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="text" name="crypto_currency" id="id_crypto_currency" required maxlength="10" value="{{ transaction.crypto_currency }}"/>
|
||||
{{ form.crypto_currency }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Amount before fee:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="decimal" name="amount_before_fee" id="id_amount_before_fee" required value="{{ transaction.amount_before_fee }}"/>
|
||||
{{ form.amount_before_fee }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Amount after fee:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="decimal" name="amount_after_fee" id="id_amount_after_fee" required value="{{ transaction.amount_after_fee }}"/>
|
||||
{{ form.amount_after_fee }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Exchange Rate:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="decimal" name="exchange_rate" id="id_exchange_rate" required value="{{ transaction.exchange_rate }}"/>
|
||||
{{ form.exchange_rate }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Fiat Currency:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="text" name="fiat_currency" id="id_fiat_currency" required maxlength="10" value="{{ transaction.fiat_currency }}"/>
|
||||
{{ form.fiat_currency }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Fiat Amount:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="decimal" name="amount" id="id_amount" required value="{{ transaction.amount }}"/>
|
||||
{{ form.amount }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Date valid:</label>
|
||||
<div class="col-sm-4">
|
||||
<input type="text" name="date_valid" id="id_date_valid" required value="{{ transaction.date_valid|date:'Y-m-d H:i:s' }}"/>
|
||||
{{ form.date_valid }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -31,7 +31,8 @@ def show(request):
|
||||
@login_required
|
||||
def edit(request, id):
|
||||
transaction = Transaction.objects.get(id=id, owner=request.user)
|
||||
return render(request,'edit.html', {'transaction':transaction})
|
||||
form = TransactionForm(request.POST or None, instance = transaction)
|
||||
return render(request,'edit.html', {'transaction':transaction, 'form': form})
|
||||
|
||||
@login_required
|
||||
def update(request, id):
|
||||
|
||||
Reference in New Issue
Block a user