Nathan,
Thanks for the iteritems() method.  I implemented that into my code.
However, 'if values != 0:' never evaluates to False.  Even though some
of the forms elements values are 0.  For example when I do a assert
False, values on one of those elements I see:

AssertionError at /rugs/cart/addpad/
[u'0']

Does that mean that the value is 0?  below is my view function and
template code:

//////////////
def addpad(request):
        if request.method == 'POST':
                pads = request.session.get('pad', [])
                for a, values in request.POST.iteritems():
                        #assert False, values
                        if values != 0:
                                opad = RugPad.objects.get(id=a)
                                s = opad.size
                                p = opad.price
                                pads.append({'size': s, 'price': p})
                                request.session['pad'] = pads
                        else:
                                assert False, "It got here" #It never gets here
                return render_to_response('addpad.html', {'spad':
request.session['pad']})

/////////////

{% for a in pad %}
<tr>
 <td>
  <select name="{{ a.id }}">
   <option value="0">---</option>
   <option value="1">1</option>
   <option value="2">2</option>
   <option value="3">3</option>
   <option value="4">4</option>
   <option value="5">5</option>
  </select> {{ a.size }} -- ${{ a.price }}
 </td>
</tr>
{% endfor %}

/////////////////////////

I'm thinking that my values variable is not a int.  I tried
int(values) but that still didn't work.  How do I get it so that
values is a int so that I can do 'if values != 0:'?

Thanks


On Jul 27, 8:49 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
> I'm not sure if I'm following what your saying...but this is what I
> think you want to do:
>
> if request.method == 'POST':
>                pads = request.session.get('pad', [])
>                for pad in pads:
>                     if request.POST[pad.id] <> '---': # the select
> name should be the pad id based on your template code
>                             # do something here ... because it wasn't
> ---
>
> On Jul 27, 5:54 pm, Greg <[EMAIL PROTECTED]> wrote:
>
> > I'm trying to loop through my POST data.  However I am having
> > difficulties.  I think my 'for' statement might be wrong.  Below is my
> > function and template code
>
> > //////////////////////// View function
>
> > def addpad(request):
> >         if request.method == 'POST':
> >                 pads = request.session.get('pad', [])
> >                 i = 0
> >                 b = 1
> >                 for a in request.POST:
> >                         if a != '---':
> >                                 opad = RugPad.objects.get(id=b)
> >                                 s = opad.size
> >                                 p = opad.price
> >                                 pads.append({'size': s, 'price': p})
> >                                 request.session['pad'] = pads
> >                         i = i + 1
> >                         b = b + 1
> >                 return render_to_response('addpad.html', {'spad':
> > request.session['pad']})
>
> > ///////////////// Template File
>
> > {% for a in pad %}
> > <tr>
> >  <td>
> >   <select name="{{ a.id }}">
> >    <option value="---">---</option>
> >    <option value="1">1</option>
> >    <option value="2">2</option>
> >    <option value="3">3</option>
> >    <option value="4">4</option>
> >    <option value="5">5</option>
> >   </select> {{ a.size }} -- ${{ a.price }}
> >  </td>
> > </tr>
> > {% endfor %}
>
> > //////////////
>
> > Notice how my 'for' statement is listed as ' for a in request.POST:
> > '.  However, when i do a 'assert False, a' it always returns the value
> > '1'.  I need to get the value of each select statement.  Such as (---,
> > 1,2,3,4,5).
>
> > Is that 'for' statement returning me the value of each select
> > statement?
>
> > Thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to