问题描述
我已经从 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 表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)