On Wed, 2008-12-24 at 09:42 -0800, JeeyoungKim wrote: > I have the following form: > > class UserInfoForm(forms.ModelForm): > password_field = forms.CharField(label='Password', > widget=forms.PasswordInput(render_value=False) > password_repeat_field = forms.CharField(label='Password(repeat)', > widget=forms.PasswordInput(render_value=False)) > > #Make them required. > password_field.required = True > password_repeat_field.required = True > > class Meta: > model = User > fields = > ('username','first_name','last_name','email','password_field','password_repeat_field') > > > By writing > password_field.required = True > password_repeat_field.required = True > in the UserFormInfo, I changed the requiredness of the password_field > and password_repeat_field to True. However, when I tried to do the > same for the fields from the model, (like username), I get an error. > > Is there any easy way to do this? Thanks.
Both model fields and form fields allow you to specify whether the value is required to be filled in at declaration time. Trying to change it afterwards is likely to lead to fairly fragile code, so you should try to avoid doing this for both forms and models. The equivalent concept for models is the "blank" parameter that you pass to the model field. For example: my_field = models.CharField(blank=False, max_length=50) Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---