ctx['orders'] = self.get_orders(self.request.user)
self.fields['email'].required = True def clean_email(self): """ Make sure that the email address is aways unique as it is used instead of the username. This is necessary because the unique-ness of email addresses is *not* enforced on the model level in ``django.contrib.auth.models.User``. """ email = self.cleaned_data['email'] try: User.objects.exclude( id=self.user.id).get(email=email) except User.DoesNotExist: return email else: raise ValidationError( _("A user with this email address already exists") ) class Meta: model = User exclude = ('username', 'password', 'is_staff', 'is_superuser', 'is_active', 'last_login', 'date_joined', 'user_permissions', 'groups') Profile = get_profile_class() if Profile: class UserAndProfileForm(forms.ModelForm): email = forms.EmailField(label=_('Email address'), required=True) def __init__(self, user, *args, **kwargs):