سؤال

I have declared a signal for the UserProfile model which updates some other fields. The stored data are coming from a web service.

 post_save.connect(user_profile_update, sender=UserProfile)

in user_profile_update, i did this:

 profile = get_object_or_404(UserProfile, user=instance) 
 profile.province = xml.duzeltilmisil #this comes from a web service
 profile.save()

and i got this error:

 'NoneType' object is not callable
 profile.save()

There is an other error but what did I do was also recursive. When I update UserProfile, it should trig user_profile_update again.

Is there any reasonable way to update those fields during the save?

هل كانت مفيدة؟

المحلول

Since you are parsing the address, it is a better approach to handle the parsing in the view, rather than as a signal.

Signals are normal used for minor updates to other models. .

So, your code can be:

profile = get_object_or_404(UserProfile, user=instance) 
profile.province = xml.duzeltilmisil #this comes from a web service

//parse the address here, and then save the models
profile.save()
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top