Search code examples
djangodjango-formschoicefieldcleaned-data

cleaned_data() doesn't have some of the entered data


I have a simple form for a user to enter in Name (CharField), Age(IntegerField), and Sex(ChoiceField). However the data that is taken from the Sex choice field is not showing up in my cleaned_data(). Using a debugger, I can clearly see that the data is being received in the correct format but as soon as I do form.cleaned_data() all sign of my choice field data is gone. Any help would be greatly appreciated. Here is the relative code:

  class InformationForm(forms.Form):
     Name = forms.CharField()
     Age = forms.IntegerField()
     Sex = forms.ChoiceField(SEX_CHOICES, required=True)

   def get_information(request, username):
       if request.method == 'GET':
           form = InformationForm()   
       else:
           form = RelativeForm(request.POST)
           if form.is_valid():
               relative_data = form.cleaned_data

Solution

  • The form that I was using in POST did not include the Sex field so of course the data dissappeared.