【发布时间】:2012-07-23 15:51:37
【问题描述】:
我想在初始化表单时获取当前 url,以便在其中找到我想要检查的字符串。 根据这个字符串,我想更改我放入 radioselect 小部件的数据。 我想根据 url 显示不同的 radioselect 选项。
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')
我的看法:
def add_function (request)
if request.method == 'POST': # If the form has been submitted...
function_form = FunctionForm(request.get_full_path,request.POST)
【问题讨论】: