I am trying to update a form field after getting a form in the POST method. 
When I am trying to update the form I am getting following error

Request Method: POST
Django Version: 1.6.6
Exception Type: TypeError
Exception Value:    
'SmsPduForm' object does not support item assignment

My Form Code is

class SmsPduForm(forms.Form):
    """
    This class generates the SMS PDU form
    """
    pduType = (('1','SMS-SUBMIT'), ('2','SMS-DELIVER'))
    encoding = (('0','7 BIT'), ('8','UCS2'))
    Address = forms.CharField(max_length=20, min_length=5, required=True, 
label="Target Address",
                               initial="+917654321")

    SMSC = forms.CharField(max_length=13, min_length=5,required=True, 
label="SMSC Address",
                        initial="+91244414")

    PDUType = forms.ChoiceField(widget=forms.RadioSelect, choices=pduType, 
required=True,
                                label="PDU Type", initial=pduType[0])

    EncodingType = forms.ChoiceField(widget=forms.RadioSelect, 
choices=encoding, required=True, label="Encoding Type",
                                     initial=encoding[0])

    Text = forms.CharField(widget=forms.Textarea(attrs={'row':6, 
'cols':50}),required=True, label="SMS Text",
                           initial="Hello", max_length=140)

    smsPDU = forms.CharField(widget=forms.Textarea(attrs={'row':6, 
'cols':50}),required=True, label="SMS PDU",
                           initial="Hello", max_length=140)

    #Meta class of the form
    class Meta:
        fields = ('Address', 'SMSC', 'PDUType',
                  'EncodingType', 'Text', 'smsPDU')

My view code is

def smsHandler(request):
    context = RequestContext(request)
    if request.method == 'POST':
        method=""
        #Do for post method else do for get method
        smsPduForm = SmsPduForm(request.POST)
        smsc = smsPduForm['SMSC'].value()
        address = smsPduForm['Address'].value()
        encodingType = smsPduForm['EncodingType'].value()
        pduType = smsPduForm['PDUType'].value()
        text = smsPduForm['Text'].value()
        smsPdu = smsPduForm['smsPDU'].value()
        print(smsc,address,encodingType,pduType,text,smsPdu)
        if "Encode" in request.POST:
            method = "encode"
            smsEncObj = SmsEncoder(encodingType, smsc, pduType, text, address )
            smsPdu = smsEncObj.generateSmsSubmitPdu()
            #SmsPduForm.clean_smsPDU()
            #Here I am updating the form
            smsPduForm['smsPDU'] = smsPdu
        elif "Decode" in request.POST:
            method = "decode"
        print("Action need to perform:",method)


        contextDic = {'forms':SmsPduForm}
        return 
render_to_response('telecom_utils/smsUtil.html',contextDic,context)
    else:
        contextDic = {'forms':SmsPduForm}
        return 
render_to_response('telecom_utils/smsUtil.html',contextDic,context)

How can i update the form ? Kindly look into the issue.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/75f83eb2-fa29-4022-9c9c-760f0060c209%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to