-1

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?

cem
  • 1,535
  • 19
  • 25
  • disable the signal, and see if the error still occurs – karthikr Apr 04 '13 at 21:37
  • karthikr, the user enters the postal address as a normal text, a webservice parses it and it gives me the city, district etc. information of the address and i want to store those information just after the update. so i think i need this signal. if i will disable the signal, i will not get any error but the address will not be parsed. – cem Apr 04 '13 at 21:39
  • Why do you need a signal to do a parsing? You can handle it better in your view. Signals are good only for minor updates, not for implementing logic – karthikr Apr 04 '13 at 21:42
  • Yeah, I am new at Django and that's a solution. If you will write the same thing as answer, it would be cool. Thank you. – cem Apr 04 '13 at 21:46

1 Answers1

0

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()
karthikr
  • 97,368
  • 26
  • 197
  • 188