title: django forms: setting a different initial form values on same page
body: <p>As you see in the html bellow, my code generates a table from data with a form in each row. When you submit the form, it posts data based on the row it was in. This works well. However, I need the initial data in the field to be different for each row. It has to be a calculated value based on the data the row is associated with. Is there maybe some django template code I can use to set this? Or is there maybe a way I can pass that value from the view?</p>
  
  <pre><code>{% for liquor in filter %}
  
  &lt;tr&gt;
  &lt;td&gt;{{ liquor.LiquorCode }}&lt;/td&gt;
  &lt;td&gt;&lt;a href="/liquors/get/{{ a.StoreID }}/{{ liquor.id }}/{{ SPI }}/"&gt;{{ liquor.BrandName }}&lt;/a&gt;&lt;/td&gt;
  &lt;td&gt;{{ liquor.VendorName }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.LiquorType }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.Proof }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.BottleSize }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.PackSize }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.OffPremisePrice }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.ShelfPrice }}&lt;/td&gt;
  &lt;td&gt;{{ liquor.GlobalTradeItemNumber1 }}&lt;/td&gt;
  &lt;td&gt;&lt;form action="/stores/quickadd/{{ a.StoreID }}/{{ liquor.id }}/{{ SPI }}/" method="post"&gt;{% csrf_token %}
  
  {{form.as_p}}
  
  
  &lt;input type="submit" name="submit" value="Add to Store"&gt;&lt;/td&gt;
  &lt;/tr&gt;
  
      {% endfor %}
  </code></pre>
  
  <p>Here is my view:</p>
  
  <pre><code>def product_list(request, store_id):
      store = Store.objects.get(StoreID=store_id)
      f = ProductFilter(request.GET, queryset=Liquor.objects.all())
      LiqSPI = StoreLiquor.objects.filter(storeID=store_id).count()
      AddLiqForm = AddLiquorForm()
  
      args = {}
      args['filter'] = f
      args['a'] = store
      args['SPI'] = LiqSPI + 1
      args['form'] = AddLiqForm
      return render(request,'UPC_filter.html', args)
  
  def quickadd(request, store_id, liquor_id, SPI):
      storeID = Store.objects.get(StoreID=store_id)
      liquorID = Liquor.objects.get(id=liquor_id)
      if request.method == "POST":
          AddLiqForm = AddLiquorForm(request.POST)
          if AddLiqForm.is_valid():
              StoreLiqID = AddLiqForm.save(commit=False)
              StoreLiqID.storeID = storeID
              StoreLiqID.liquorID = liquorID
              StoreLiqID.StorePrice = request.POST.get('StorePrice', '')
              StoreLiqID.SPI = SPI
              StoreLiqID.save()
              return HttpResponseRedirect('/stores/UPC_Scan/%s' % store_id)
  </code></pre>