I would like to check the URL path so I can create the form base on it. In the view, we can use the request parameter to get the URL path, is there a similar way so we can get the current URL inside forms.py?
URL=??
if URL == 'phones':
brand_choises= (('Sumsung', 'Sumsung'),
('Iphon', 'Iphone'),)
if URL == 'cars':
brand_choises= (('Honda', 'Honda'),
('Toyota', 'Toyota'),)
class Productform(forms.ModelForm):
brand=forms.ChoiceField(choices=brand_choises,widget=forms.Select(attrs={'class':'products'}))
class Meta:
model = Product
def __init__(self, *args, **kwargs):
super(ProductForm, self).__init__(*args, **kwargs)
self.fields['brand'].choices = brand_choises