使用SelectDateWidget的Django表单字段 [英] Django form field using SelectDateWidget
问题描述
我从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.
这是来自我的应用程序:
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
我在做什么错?检查表格/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。该解决方案会导入其他内容,因此引用只是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表单字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!