Al final he conseguido solucionar el problema de los valores en blanco. Compruebo el tamaño del valor, de forma que si es igual a 0, utiliza el valor anterior
forms.py
Código Python:
Ver originalclass UserEditForm(UserChangeForm):
class Meta:
model = Profiles
fields = ('username', 'first_name', 'last_name', 'email', 'url',
'avatar',)
exclude = ('password',)
def __init__(self, user, *args, **kwargs):
super(UserEditForm, self).__init__(*args, **kwargs)
self.user = user
def clean(self):
cleaned_data = self.cleaned_data
for field, value in list(cleaned_data.items()):
old_value = getattr(self.user, field)
if len(value) > 0:
cleaned_data[field] = value
else:
cleaned_data[field] = old_value
return cleaned_data
def clean_password(self):
return ""
views.py
Código Python:
Ver originalclass UserEdit(UpdateView):
model = Profiles
form_class = UserEditForm
success_url = reverse_lazy('profile')
template_name = 'profile/edit.html'
def get_form_kwargs(self):
kwargs = super(UserEdit, self).get_form_kwargs()
kwargs['user'] = self.request.user
return kwargs
def get_object(self, queryset=None):
return self.request.user