javascript - Django select foreign key with bootstrap modal -
i'm having problem this: want create modal pick related object foreign key. modal shows up, render form , list results. search button close modal , don't know how pick object radiobox. code below:
pay_form.html
<div class="form-inline"> <label for="idticket" style="margin-right: 5px">ticket:</label> {{ payform.idticket }} <a data-toggle="modal" href="searchticket" type="button" class="btn btn-default btn-xs"> <i class="icon-search"></i> </a> </div> <a href="/payments/cash" class="btn btn-default">cancel</a><input type="submit" class="btn btn-primary" value="save"/> </form> <div id="searchticket" class="modal fade" style="display: none"> {% include "payments/ticket_search.html" %} </div><!-- /.modal -->
search_ticket.html
<div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> <h4 class="modal-title">selecct ticket</h4> </div> <div class="modal-body"> <form action="" method="get"/> <fieldset> <div class="form-inline"> <label>ticket:</label> <input type="text" name="idticket"/> </div> <input type="submit" class="btn btn-info" value="search"/> </fieldset> </form> <table class="table table-striped table-condensed"> <thead> <tr> <th>ticket</th> <th>date</th> <th>amount</th> </tr> </thead> <tbody> {% result in results %} <tr> <th><input type="radio" value="{{result.ticket}}"></th> <th>{{result.idticket}}</th> <th>{{result.date}}</th> <th>{{result.amount}}</th> </tr> {% endfor %} </tbody> </table> </div> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">cancel</button> <button type="button" class="btn btn-primary">selecct</button> </div> </div><!-- /.modal-content --> </div><!-- /.modal-dialog -->
views.py
def ticket_search(request): if request.method == 'get' , 'idticket' in request.get: sform = searchticketform(request.get) if sform.is_valid(): idticketf = sform.cleaned_data.get('idticket') qs = ticket.objects.all() if idticketf not none: qs = qs.filter(idticket__icontains=idticketf) qs = qs.order_by('idticket',) else: qs = ticket.objects.all().order_by('idticket',) else: sform = searchticketform() qs = ticket.objects.all().order_by('idticket',) return render(request, 'payments/ticket_search.html', {'sform':sform,'results':qs})
so theres 2 things:
1) perform search modal window.
2) return selected value.
Comments
Post a Comment