Can't put data into tuple in forms.py Django
I'm currently getting the data from an external API (also developed with django) and put it into a tuple and it's showing it in the HTML but when i use that info into a form and post it, it always shows that field has "none"
(Views.py)
def register_user(request):
if request.method == "POST":
if "register" in request.POST:
mainForm = mainUserForm(request.POST)
form = userForm(request.POST)
if mainForm.is_valid() and form.is_valid():
user = User.objects.create_user(mainForm.cleaned_data['username'],mainForm.cleaned_data['email'],mainForm.cleaned_data['password'])
if form.cleaned_data['userType'] == 2:
user.is_superuser = True
user.is_staff = True
user.save()
userextended = models.commonUserModel(user = user, firstName = form.cleaned_data['firstName'], lastName = form.cleaned_data['lastName'],
phoneNumber = form.cleaned_data['phoneNumber'], rut = form.cleaned_data['rut'],
userType = form.cleaned_data['userType'], company = form.cleaned_data['company'])
userextended.save()
return redirect('registerUser')
else:
return redirect('registerUser')
context = {}
context['mainForm'] = mainUserForm
context['form'] = userForm()
context['userExtend'] = commonUserModel.getUserExtended(request.user.id)
return render(request, template_name='auth/register.html', context= context)
(Models.py)
class commonUserModel(models.Model):
user = models.OneToOneField(User, on_delete = models.CASCADE, related_name="extend")
company = models.IntegerField()
firstName = models.CharField(max_length=30)
lastName = models.CharField(max_length=30)
phoneNumber = models.CharField(max_length=20)
rut = models.CharField(max_length=20, unique= True)
userType = models.IntegerField(choices=CLIENT_TYPES, default=1)
disabled = models.BooleanField(default = False)
(Forms.py)
class userForm(forms.ModelForm):
def __init__(self,company_choices, *args, **kwargs):
choices=[]
super(userForm, self).__init__(*args, **kwargs)
self.fields['testeo']=forms.ChoiceField(choices=((0, 'Normal' ),
(1, 'Especial'),))
testeo= forms.ChoiceField()