Let’s say you have a field defined as the following in your model:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RegisterForm(forms.ModelForm): | |
first_name = forms.CharField(max_length=User._meta.get_field('first_name').max_length) |