我需要使用Django表单中名为CustomModelChoiceField的自定义字段的帮助。我试图重写ModelChoiceField的label_from_instance
方法
我的表格:
from django import forms
from myfolder.otherfolder.fields import CustomModelChoiceField
class MyForm(forms.Form):
# I had to override init to get some paramaters, so I'll simplify it
def __init__(self, *args, **kwargs):
#skipped querying code
self.fields['custom'] = CustomModelChoiceField(queryset = custom_dates,
required = False,
widget = forms.Select(attrs={"onChange":'changeCalendar()'}),
label = "Choose a date")
我的习惯字段.py文件(与表单.py,并且import语句起作用)。取自docs:
^{pr2}$当我试图查看页面时,我得到:
'module' object has no attribute 'CustomModelChoiceField'
可能是我的字段.py在错误的文件夹里或者我在子类化方面很差劲。有什么想法吗?在
目前没有回答
相关问题 更多 >
编程相关推荐