0

i have a dropdown list having the store name,when i select a store from that i need store_key from that select value

def store_list(request):
     displaystores=stores.objects.all()
     if request.POST:
         store_pk_list = request.POST.getlist('stores', None)
         print(request.POST.getlist('stores.unit_key', None))

         selected_store_obj_list = stores.objects.filter(pk__in=store_pk_list)
         print(selected_store_obj_list)
        
    return render(request,'storelist.html',{'stores':displaystores})

html

 <form action="" method="post">
  {% csrf_token %}
--store_name--
 {%for result in stores%}
  <option value="{{result.unit_key}}">{{result.unit_name}}</option>
  {%endfor%}

</select>

NKSM
  • 5,422
  • 4
  • 25
  • 38

1 Answers1

0

Once you get the form through the POST, validate the data and then use them, Check this,

getting value from form field

SANGEETH SUBRAMONIAM
  • 1,098
  • 1
  • 9
  • 10