I want to create a form with a select box populated from a query that
I pass from the view.
For example:
if country == 'Canada':
methods = ShippingMethod.objects.filter(
delivery_time__lte=time_avail_hours,
abbrev__contains='SC'
)
else:
methods = ShippingMethod.objects.filter(
delivery_time__lte=time_avail_hours,
abbrev__contains='SU'
)
formShip = ShippingMethodForm(initial={
'queryset': methods,
})
My Form is defined as:
class ShippingMethodForm(forms.Form):
ship_method = forms.ModelChoiceField
(queryset=ShippingMethod.objects.none())
def __init__(self, *args, **kwargs):
super(ShippingMethodForm, self).__init__(*args, **kwargs)
self.fields["ship_method"].queryset =
ShippingMethod.objects.filter(something)
However the queryset I define in the view is not being used by
ShippingMethodForm, without the __init__ method shown. I don't know
how to pass the "initial" argument to the init method. What is the
correct way to do this?
Thanks
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---