use forms.SplitDateTimeField for date_valid in Transaction Add and Edit
fixes #1
This commit is contained in:
@@ -2,18 +2,20 @@ from django import forms
|
|||||||
import datetime
|
import datetime
|
||||||
from apps.transactions.models import Transaction
|
from apps.transactions.models import Transaction
|
||||||
from apps.rates.models import ExchangeRate
|
from apps.rates.models import ExchangeRate
|
||||||
#from datetimepicker.widgets import DateTimePicker
|
|
||||||
#from django.contrib.admin.widgets import AdminDateWidget
|
|
||||||
|
|
||||||
class TransactionForm(forms.ModelForm):
|
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:
|
class Meta:
|
||||||
model = Transaction
|
model = Transaction
|
||||||
fields = "__all__"
|
fields = "__all__"
|
||||||
|
|
||||||
# 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))
|
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})]
|
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})]
|
fiat_currencies = [(x, x) for x in sorted({ex.fiat_currency for ex in exchangerates})]
|
||||||
@@ -22,4 +24,3 @@ class TransactionForm(forms.ModelForm):
|
|||||||
'fiat_currency': forms.Select(choices = fiat_currencies),
|
'fiat_currency': forms.Select(choices = fiat_currencies),
|
||||||
'crypto_currency': forms.Select(choices = crypto_currencies),
|
'crypto_currency': forms.Select(choices = crypto_currencies),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<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">
|
<div class="col-sm-4">
|
||||||
{{ form.date_valid }}
|
{{ form.date_valid }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<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">
|
<div class="col-sm-4">
|
||||||
{{ form.date_valid }}
|
{{ form.date_valid }}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user