Let’s say you have a field defined as the following in your model:
class User(models.Model): | |
first_name = models.CharField(max_length=40, null=True) |
You can then use the max_length in your ModelForm like this:
class RegisterForm(forms.ModelForm): | |
first_name = forms.CharField(max_length=User._meta.get_field('first_name').max_length) |