def __init__(self, *args, **kwargs):
super(ShippingMethodForm, self).__init__(*args, **kwargs)
if self.fields['country'].initial == 'Canada':
filter_kwargs = { 'delivery_time__lte': time_avail_hours,
'abbrev__contains'='SC' }
elif: ...
else: ..
self.fi
For the record, here's what works:
In views.py:
if country == 'Canada':
delivery_time__lte=time_avail_hours
abbrev__contains='SC'
formShip = ShippingMethodForm(delivery_time__lte, abbrev__contains)
Then in models.py:
class ShippingMethodForm(forms.Form):
# tricky
oops! missing the filter_string arg in __init__. After I added that,
I get:
ValueError .too many values to unpack
On May 11, 4:27 pm, adrian wrote:
> I tried in the view:
>
> filter_string = "delivery_time__lte=time_avail_hours,
> abbrev__contains='SC'"
> formShip = ShippingMethodForm(fil
I tried in the view:
filter_string = "delivery_time__lte=time_avail_hours,
abbrev__contains='SC'"
formShip = ShippingMethodForm(filter_string)
Then the form def is:
class ShippingMethodForm(forms.Form):
# tricky thing done here to change queryset based on ticket date
and destination
shi
This should fix it.
def __init__(self, something, *args, **kwargs):
super(ShippingMethodForm, self).__init__(*args, **kwargs)
self.fields["ship_method"].queryset =
ShippingMethod.objects.filter(something)
when you initiate the form, you do it like this:
form = ShippingMethodForm(
5 matches
Mail list logo