خرید بک لینک

Vote count: 0

I have this simple Django form for filtering data with GET form:

from reservations.models import Reservation, ServiceType
from django import forms


PAYMENT_OPTIONS = (
    ('CASH', 'Cash'),
    ('ROOM', 'Charge to room'),
    ('ACCOUNT', 'Account'),
    ('VISA', 'Visa'),
    ('MASTERCARD', 'Mastercard'),
    ('AMEX', 'Amex'))

    class FilterForm(forms.Form):
        def __init__(self, *args, **kwargs):
            super(FilterForm, self).__init__(*args, **kwargs)
            self.fields['service_date_from'].widget.attrs['class'] = 'datepicker'
            self.fields['service_date_to'].widget.attrs['class'] = 'datepicker'

        service_date_from = forms.CharField()
        service_date_to = forms.CharField()
        payment_options = forms.MultipleChoiceField(widget=forms.CheckboxSelectMultiple,
                                             choices=PAYMENT_OPTIONS)

And then in the template:

<fieldset>
    <label>{{form.payment_options.label}}</label>
    {{form.payment_options}}
</fieldset>

The HTML:

<fieldset>
   <label>Payment options</label>
   <ul id="id_payment_options">
      <li><label for="id_payment_options_0"><input id="id_payment_options_0" name="payment_options" type="checkbox" value="CASH"> Cash</label></li>
      <li><label for="id_payment_options_1"><input id="id_payment_options_1" name="payment_options" type="checkbox" value="ROOM"> Charge to room</label></li>
      <li><label for="id_payment_options_2"><input id="id_payment_options_2" name="payment_options" type="checkbox" value="ACCOUNT"> Account</label></li>
      <li><label for="id_payment_options_3"><input id="id_payment_options_3" name="payment_options" type="checkbox" value="VISA"> Visa</label></li>
      <li><label for="id_payment_options_4"><input id="id_payment_options_4" name="payment_options" type="checkbox" value="MASTERCARD"> Mastercard</label></li>
      <li><label for="id_payment_options_5"><input id="id_payment_options_5" name="payment_options" type="checkbox" value="AMEX"> Amex</label></li>
   </ul>
</fieldset>

The problem is, when I select two or more payment options, I only get the last one in the url.

So for example, when I select Cash and Account, I'd get something like ?payment_options=ACCOUNT and not ?payment_options=CASH&payment_options=ACCOUNT

How can I fix that? I'm thinking that payment_options should be payment_options[] but don't know how to do that.

asked 1 min ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: شنبه 15 اسفند 1394 ساعت: 9:14

صفحه بندی