Re: change query for ModelChoiceField

2009-05-11 Thread krylatij
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

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
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

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
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

Re: change query for ModelChoiceField

2009-05-11 Thread adrian
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

Re: change query for ModelChoiceField

2009-05-11 Thread google torp
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(