I currently have a form that allows the user to edit their profile (django-profiles). The form is working great, except that I've put a switch in place for States and Provinces depending on whether ot not the user picks Canada or the US.
In my model, I have both State and Province set so that in the table there are 2 separate fields.
In my save method I have the following:
def user_created(sender, user, request, **kwargs):
form = RegistrationFormZ(request.POST)
....stuff here.....
if form.data["country"] == 'US':
data.state = form.data["state"]
data.provinces = None
if form.data["country"] == 'CA':
data.provinces = form.data["provinces"]
data.state = None
....stuff here....
data.save()
user.first_name = form.data['first_name']
user.last_name = form.data['last_name']
user.save()
from registration.signals import user_registered
user_registered.connect(user_created)
The if statements are not working as I expected they would on save.
What's happening is that it correctly saves the value of the option that was selected (state/province) but then fails to update the opposing one to an empty value.
So for example let's say I had a user who had a Canadian address, and then updated it to the US address. The US state gets properly saved, but province does not get updated to None.