Can we define multiple models in the “Meta class” part of a Form ?
Here is my example:
from django import forms
from django.contrib.auth.models import User , Group
from django.forms import ModelForm
from django.utils.translation import ugettext as _
from profiles.models import Student , Tutor
class RegistrationForm(ModelForm):
email = forms.EmailField(label=_('Email Address:'))
password = form.CharField(label=_('Passsword:') , widget = forms.PasswordInput(render_value = False))
password1 = form.CharField(label=_('Verify Passsword:') , widget = forms.PasswordInput(render_value = False))
class Meta:
model = [Student , Tutor] ## IS THIS TRUE ???
No. But you don’t need to. Instead of instantiating and validating a single form, do it for each type of form you need to support.
If this means field names are duplicated across forms, use form prefixes to sort that out.