use forms.SplitDateTimeField for date_valid in Transaction Add and Edit
fixes #1
This commit is contained in:
@@ -2,17 +2,19 @@ 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
|
||||
|
||||
class TransactionForm(forms.ModelForm):
|
||||
date_valid = forms.SplitDateTimeField(
|
||||
label="Date and Time of Transaction",
|
||||
input_time_formats=['%H:%M'],
|
||||
widget=forms.SplitDateTimeWidget(
|
||||
date_attrs={'type': 'date'},
|
||||
time_attrs={'type': 'time'},
|
||||
time_format='%H:%M'))
|
||||
|
||||
class Meta:
|
||||
model = Transaction
|
||||
fields = "__all__"
|
||||
|
||||
# https://stackoverflow.com/a/52702275/1632368
|
||||
#date_valid = forms.DateField(widget=AdminDateWidget())
|
||||
fields = "__all__"
|
||||
|
||||
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})]
|
||||
@@ -22,4 +24,3 @@ class TransactionForm(forms.ModelForm):
|
||||
'fiat_currency': forms.Select(choices = fiat_currencies),
|
||||
'crypto_currency': forms.Select(choices = crypto_currencies),
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Date valid:</label>
|
||||
<label class="col-sm-2 col-form-label">{{ form.date_valid.label }}:</label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.date_valid }}
|
||||
</div>
|
||||
|
||||
@@ -71,7 +71,7 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group row">
|
||||
<label class="col-sm-2 col-form-label">Date valid:</label>
|
||||
<label class="col-sm-2 col-form-label">{{ form.date_valid.label }}:</label>
|
||||
<div class="col-sm-4">
|
||||
{{ form.date_valid }}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user