使用SelectDateWidget的Django表单字段

使用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.

这是来自我的应用程序:

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.