python - Django bootstrap3_datetime widget in admin site doesn't pass form data -
i'm trying replace standard adminsplitdatetime widget in admin site better functionality (basically want display 'available' dates in calender couldn't find how default picker). decided use bootstrap3_datetime widget.
after overriding field use new widget, doesn't seem transferred 'clean' method (isn't in self.cleaned_data) validation.
models.py
publish_time = models.datetimefield('date publish')
admin.py
class myform(forms.modelform): def __init__(self, *args, **kwargs): super(myform, self).__init__(*args, **kwargs) bad_dates = [] #populating bad_dates application logic def clean(self): # return none when using new widget. # when working default widget, have correct value. publish_time = self.cleaned_data.get('publish_time', none) publish_time = forms.datetimefield(widget=datetimepicker(options= {"format": "dd-mm-yyyy hh:mm", "startdate": timezone.now().strftime('%y-%m-%d'), "disableddates": bad_dates, }) class mymodeladmin(admin.modeladmin): form = myform admin.site.register(mymodel, mymodeladmin)
html-wise, widget works , text field populated correct date (and 'bad_dates' disabled). problem seems isn't saved on form.
i tried initializing widget in init method doing:
self.fields['publish_time'].widget = datetimepicker(options=...)
but result same.
what missing here? possible modify widgets in admin site?
thanks!
update: i've analysed post request sent using each of widgets. in default admin widget, see generates 2 fields: "publish_time_0" (for date) , "publish_time_1" (for time). in bootstrap3 widget, single "publish_time" field sent.
i'm assuming admin site understands field datetimefield (from models), looks id_0 , id_1 , that's why fails. make sense? there anyway around it?
Comments
Post a Comment