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单元测试 2022-01-01
- 我如何卸载 PyTorch? 2022-01-01
- 如何使用PYSPARK从Spark获得批次行 2022-01-01
- ";find_element_by_name(';name';)";和&QOOT;FIND_ELEMENT(BY NAME,';NAME';)";之间有什么区别? 2022-01-01
- YouTube API v3 返回截断的观看记录 2022-01-01
- 我如何透明地重定向一个Python导入? 2022-01-01
- CTR 中的 AES 如何用于 Python 和 PyCrypto? 2022-01-01
- 使用 Cython 将 Python 链接到共享库 2022-01-01
- 使用公司代理使Python3.x Slack(松弛客户端) 2022-01-01
- 检查具有纬度和经度的地理点是否在 shapefile 中 2022-01-01