更新时间:2023-11-30 15:56:46
您应该查看django / contrib / admin / widgets.py。您将在此处找到管理站点小部件。然后在表单中输入以下内容:
You should have a look to django/contrib/admin/widgets.py You will find here the admin site widgets. Then in you form, make something like:
from django.contrib.admin.widgets import AdminDateWidget
class MyForm(ModelForm):
class Meta:
widgets = {
'date': AdminDateWidget(),
}
确保模板包含所需的媒体文件(css,js)
Make sure that your template includes the required media files (css, js)
我还建议查看 django-floppyforms ,如果您想要更好的小部件,这是一个非常不错的库
I also recommend to look at django-floppyforms which is a very nice lib if you want better widgets