【发布时间】:2009-09-18 05:02:25
【问题描述】:
我正在使用 Django 配置文件,我需要在配置文件表单中进行一些更改。
在正常情况下,我的表单完全没问题,但现在我想换个垃圾,添加 jquery 以重新填充选择表单。
问题是 Django Profile 从模型中创建表单,所以我想在选择表单中添加一个属性 id(我还没有),但是然后选择不显示选项(值),我没有明白为什么,选择表单会从另一个带有 FK 的模型中获得价值。
谢谢大家 :), 对不起我的英语
我的自定义部分是:
def __init__(self, *args, **kwargs):
super(_ProfileForm, self).__init__(*args, **kwargs)
self.fields['birth_date'].widget = widget=SelectDateWidget(years=range(datetime.date.today().year,1900,-1))
self.fields['sector'].widget= forms.Select(attrs={'onchange':'get_vehicle_color();'})
django-profiles/profiles/utils.py
#....
def get_profile_form():
"""
Return a form class (a subclass of the default ``ModelForm``)
suitable for creating/editing instances of the site-specific user
profile model, as defined by the ``AUTH_PROFILE_MODULE``
setting. If that setting is missing, raise
``django.contrib.auth.models.SiteProfileNotAvailable``.
"""
profile_mod = get_profile_model()
class _ProfileForm(forms.ModelForm):
class Meta:
model = profile_mod
exclude = ('user',) # User will be filled in by the view.
def __init__(self, *args, **kwargs):
super(_ProfileForm, self).__init__(*args, **kwargs)
self.fields['birth_date'].widget = widget=SelectDateWidget(years=range(datetime.date.today().year,1900,-1))
self.fields['sector'].widget= forms.Select(attrs={'onchange':'get_sector_code();'})
return _ProfileForm
【问题讨论】:
标签: django django-models django-forms