Django: Pobierz bieżący adres URL, gdy w formularzu pojawi się widget
Chcę pobrać bieżący adres URL, gdy inicjuję mój formularz, aby znaleźć w nim ciąg, który chcę sprawdzić. W zależności od tego ciągu chcę zmienić dane umieszczone w widżecie radioselect. Chciałbym wyświetlić różne wybory radioselect w zależności od adresu URL.
class FunctionForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
# get url
url=request.get_full_path
# treat url
string = treat_url(url)
if (string=='ATC'):
self.fields['function_name'].queryset= FUNCTION_ATC_CHOICES
if (string=='ATS'):
self.fields['function_name'].queryset= FUNCTION_ATS_CHOICES
super(FunctionForm,self).__init__(*args,**kwargs)
#function_name = forms.ChoiceField(widget=RadioSelect,choices=FUNCTION_ATC_CHOICES)
class Meta :
model = Function
exclude =('session_number')
Mój widok :
def add_function (request)
if request.method == 'POST': # If the form has been submitted...
function_form = FunctionForm(request.get_full_path,request.POST)