Re: Using forloop counter to index into a query set

2008-09-30 Thread Malcolm Tredinnick
On Tue, 2008-09-30 at 08:05 -0700, SnappyDjangoUser wrote: > Hi Malcolm, > > You suggested: > > > set up the data structures > > you pass to your view a bit differently so that you can loop over the > > forms and the products simultaneously (that is, pull apart the formset > > forms and zip the

Re: Using forloop counter to index into a query set

2008-09-30 Thread SnappyDjangoUser
Malcolm, Carl and Felix, Thanks for the help! I figured out a solution to my above problem by using the suggested for loop approach to build the tuple of products and forms. It may not be the most elegant python code, but it is working and readable. # Build a tuple of products and forms for ea

Re: Using forloop counter to index into a query set

2008-09-30 Thread felix
On Sep 30, 9:36 pm, SnappyDjangoUser <[EMAIL PROTECTED]> wrote: >  In the example > above you assume that both p and v belong to products.   I just put them into a combined array called "products" > In my case, > that is not the case.  I have a queryset of products that contains the > vendor

Re: Using forloop counter to index into a query set

2008-09-30 Thread SnappyDjangoUser
This is extremely helpful! I didn't know this was possible in Django to create a tuple and loop through both items using a for loop in the template. Thank you! I am currently hung up on one last part, however. In the example above you assume that both p and v belong to products. In my case, t

Re: Using forloop counter to index into a query set

2008-09-30 Thread felix
malcom is suggesting this: def view(request): blah blah blah ... zipped = [] for p in products: v = find the vendor for this product zipped.append( ( p, v) ) # add them as a tuple # or more pythonically if its easy to find your vendor: zipped = [ (p, vendor for

Re: Using forloop counter to index into a query set

2008-09-30 Thread Carl Meyer
On Sep 30, 11:05 am, SnappyDjangoUser <[EMAIL PROTECTED]> wrote: > > set up the data structures > > you pass to your view a bit differently so that you can loop over the > > forms and the products simultaneously (that is, pull apart the formset > > forms and zip them together with the product entr

Re: Using forloop counter to index into a query set

2008-09-30 Thread SnappyDjangoUser
Hi Malcolm, You suggested: > set up the data structures > you pass to your view a bit differently so that you can loop over the > forms and the products simultaneously (that is, pull apart the formset > forms and zip them together with the product entries in the view). This is exactly what I li

Re: Using forloop counter to index into a query set

2008-09-30 Thread Malcolm Tredinnick
On Mon, 2008-09-29 at 17:31 -0700, SnappyDjangoUser wrote: > Hi Folks, > > How can I use a forloop counter to index into a query set as in the > example below? > > (I know this code does not work, but I want to do something of the > sort): > > {% for form in quote_product_formset.forms %} >

Re: Using forloop counter to index into a query set

2008-09-29 Thread SnappyDjangoUser
Yes, product is an array of many entries. It is actually a queryset that is passed to the template and I am trying to access a specific entry. I have not worked with custom tags before, but I will start reading up on it. On Sep 29, 6:12 pm, felix <[EMAIL PROTECTED]> wrote: > it might be easies

Re: Using forloop counter to index into a query set

2008-09-29 Thread felix
it might be easiest to write a custom tag there {% vendor_of_product product forloop.counter %} is product an array ? On Sep 30, 2:31 am, SnappyDjangoUser <[EMAIL PROTECTED]> wrote: > Hi Folks, > > How can I use a forloop counter to index into a query set as in the > example below? > > (I know