Django form field using SelectDateWidget(使用 SelectDateWidget 的 Django 表单字段)
问题描述
我已经从 Django 安装了最新的 SVN 分支,其中包括新的表单.我正在尝试使用 django.forms.extras.widgets 中的 SelectDateWidget,但该字段显示为普通的 DateInput 小部件.
I've installed the latest SVN branch from Django which includes the new forms. I'm trying to use the SelectDateWidget from django.forms.extras.widgets but the field is showing up as a normal DateInput widget.
这是我的应用程序中的 forms.py:
Here is the forms.py from my application:
from django import forms
from jacob_forms.models import Client
class ClientForm(forms.ModelForm):
DOB = forms.DateField(widget=forms.extras.widgets.SelectDateWidget)
class Meta:
model = Client
我做错了什么?检查 forms/extras/widgets.py 我看到 SelectDateWidget 类存在.
What am I doing wrong? Checking the forms/extras/widgets.py I see the SelectDateWidget class exists.
推荐答案
真正的问题是不能以这种方式引用 SelectDateWidget.更改代码以不同方式引用它解决了我的问题:
The real problem was that SelectDateWidget can't be referenced this way. Changing the code to reference it differently solved my problem:
from django.forms import extras
...
DOB = forms.DateField(widget=extras.SelectDateWidget)
这似乎是一个限制,您不能从导入的包中引用 package.package.Class.该解决方案导入 extras,因此引用只是 package.Class.
This seems to be a limitation that you can't reference package.package.Class from an imported package. The solution imports extras so the reference is just package.Class.
这篇关于使用 SelectDateWidget 的 Django 表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 SelectDateWidget 的 Django 表单字段


基础教程推荐
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 筛选NumPy数组 2022-01-01
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01