我有以下表格:
class EmailPreferences(forms.ModelForm):
""" Base form used for fields that are always required """
def __init__(self, *args, **kw):
super(EmailPreferences, self).__init__(*args, **kw)
class Meta:
model = teacher_email_preferences
exclude = ['id', 'c_user']
def save(self, force_insert=False, force_update=False, commit=True):
obj = super(EmailPreferences, self).save(commit=commit)
return obj
如您所见,型号名称是固定的,即teacher_email_preferences
. 但我的网站有两种类型的用户,一种Teacher
是Student
. 我不想创建单独的表单。所以我想student_email_preferences
在启动此表单时将模型更改为。做的时候如何在这里传递模型form = EmailPreferences()
?