modelform selection options

24 views
Skip to first unread message

sum abiut

unread,
Feb 15, 2018, 7:02:03 PM2/15/18
to django...@googlegroups.com
I have a model.py
class selection(models.Model):
    select=(
    (A','A'),
    ('B','B'),
    ('C','C'),
   
  
    )

options=models.CharField(max_length=7,choices=select)


and form.py

class order(forms.ModelForm):
    class Meta:
        model=selection
        fields=('Pay_options,)


I want to write a view.py that check the form for the choice that is selected but i don't know how to get started. for example if a user select option A, i want to perform some query. I want to know how to check for the options that are selected before i can performing a query. Appreciate any assistances.

cheers,

sum abiut

unread,
Feb 17, 2018, 6:01:47 PM2/17/18
to django...@googlegroups.com

Ok now i have written my view,py

def payhistory(request):
    paynum=selection.objects.all()
    num=request.POST.get('dropdown')
    if request.method=='GET':
        form=paynumberform()
    else:
        select=selection.objects.get(num=num)
        #do someting
        return render(request,'displaypayhistory.html',locals())

    return render(request,'payhistory.html',{'form':form,'paynum':paynum})


and my template 'payhistory.html

<form action="{%url 'payhistory'%}" method ="POST">{%csrf_token%}
  <table>
    <tr><td>Pay Number:</td>
      <td>
    <select name='dropdown'>
      {%for paynum in paynum%}

      <option value="{{paynum.num}}">{{paynum.num}}</option>
      {%endfor%}
    </select>
</td>


    <td><input type="submit" value="Process"/></td>

</tr>
  </table>
</form>


i manage to load the form, but the drop down list elements are not showing.


cheers,


--

Reply all
Reply to author
Forward
0 new messages