Open Luis-Palacios opened 9 years ago
Here is what I did for a quick work around, You can even use some options for each field (I wanted meridian and AM PM display for the time field):
from datetimewidget.widgets import TimeWidget, DateWidget
from django import forms
class AmPmSuitSplitDateTimeWidget(forms.SplitDateTimeWidget):
def __init__(self, attrs=None, options=None, *args, **kwargs):
widgets = [DateWidget(options=options), TimeWidget(options={'showMeridian': True,
'format': "HH:ii P"})]
forms.MultiWidget.__init__(self, widgets, attrs)
how did you get that non-bootstrap theme on top?
Hi,
I have encountered the same problem, here is the code I use now in my admin forms to avoid the "Enter a list of values" error :
from django import forms
from django.contrib import admin
from datetimewidget.widgets import DateTimeWidget
from .models import *
class TemperatureReportAdminForm(forms.ModelForm):
class Meta:
model = TemperatureReport
fields = '__all__'
def __init__(self, *args, **kwargs):
super(TemperatureReportAdminForm, self).__init__(*args, **kwargs)
self.fields['measured_at'] = forms.DateTimeField()
self.fields['measured_at'].widget = DateTimeWidget(usel10n = True,
bootstrap_version=3)
class TemperatureReportAdmin(admin.ModelAdmin):
class Media:
js = ('https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js',
'bootstrap-3.3.5-dist/js/bootstrap.js',)
css = {'all': ('bootstrap-3.3.5-dist/css/bootstrap.css',)}
form = TemperatureReportAdminForm
admin.site.register(TemperatureReport, TemperatureReportAdmin)
While using DateTimeInput (default for admin) it actually splits the date and time fields as id_fieldName_0 as date field and id_fieldName_1 as time field. When this DateTimeWidget is used, the post data contains only fieldName as single value, when django expects list of values. Hence in django admin, DateTimeWidget will always throw ValidationError to send values as list. (Tested in Django 1.8 with l10n false in settings)
I have this fixed for admin, I'll push the update in a second
What i've been doing it is applying trough raw javascript overriding the change_form.html from the admin with:
$('#id_date_0').datetimepicker({ format: 'DD/MM/YYYY' });
$('#id_date_1').datetimepicker({ format: 'HH:mm:SS' });
Should this be closed?
Hello and thank you for your awesome widget,
I am trying to use your widget in the admin for this i am trying via a form in the following way:
this produce the following output:
at client side it all works great but once i try to save:
i believe this is because normally in the admin datetime field is repsented by two inputs one for time and one for date is there and easy workaround for this?