Tips
For dynamic forms, check out modelform_factory:
from django.forms.models import modelform_factory
MyUserForm = modelform_factory(MyUser, fields=['username', 'email'])
def CustomLogicValidationForm(models.ModelForm):
def clean_username(self):
username = self.cleaned_data['username']
if "aldaran" == username:
raise forms.ValidationError("aldaran is a super username!")
return username
MyUserForm2 = modelform_factory(
MyUser,
form=CustomLogicValidationForm,
fields=['username', 'email']
)
For more infomation, see:
And perhaps… Nicer dynamic forms in django