Reputation: 37464
I'm overriding my model admin form in order to change the format of the displayed time of a TimeField
field:
class myTimeForm(forms.ModelForm):
start_time = forms.TimeField(widget=forms.TimeInput(format='%H:%M'))
class Meta:
model = MyModel
class MyModelAdmin(admin.ModelAdmin):
form = myTimeForm
Now, the now
and the clock button I had with the default form have disappeared (in the screenshot below Start time
is with the overridden widget, End time
with the default one.
What did I miss?
Upvotes: 3
Views: 4296
Reputation: 308779
The Django admin uses the AdminTimeWidget
instead of forms.TimeInput
. Try changing your code to the following:
from django.contrib.admin.widgets import AdminTimeWidget
class myTimeForm(forms.ModelForm):
start_time = forms.TimeField(widget=AdminTimeWidget(format='%H:%M'))
class Meta:
model = MyModel
Upvotes: 4