KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
15 class Profile(models.Model): 16 """ 17 User profile model 18 """ 19 user = models.ForeignKey(User, unique=True) 20 country = models.CharField('Country', blank=True, null=True, default='',\ 21 max_length=50, choices=country_list()) 22 is_active = models.BooleanField("Email Activated") I have a model like above with country set to blank=True, null=True . However, in the form that is presented to the end user, I required the country field to be completed. So I redefine the field in the Model Form like this to 'force' it to become required: 77 class ProfileEditPersonalForm(forms.ModelForm): 78 79 class Meta: 80 model = Profile 81 fields = ('email', 82 'sec_email', 83 'image', 84 'first_name', 85 'middle_name', 86 'last_name', 87 'country', 88 'number', 89 'fax',) 90 98 country = forms.ChoiceField(label='Country', choices = country_list()) So the country field is just an example (there are tons of them). Is there a better more DRY way of doing this?
Tags (comma-separated)
Save Edits
Cancel