我是 django 的新手,对如何在某种情况下使用视图有疑问:
我有一个加载轨道文件的视图。轨道以不同的方式分解,我想在地图中一一显示。用户必须填写具有特点的表格的方式。当一个结束时,我想加载下一个直到它完成。我不确定在这种情况下必须使用的结构。
def acoplar_track(request, track_id):
track = get_object_or_404(Track, id=track_id)
x=Xarxa(track.zona.nom) #an object from a custom library
...
#split the track in different ways
...
newWays = x.getTrackWays(); # a list with the ways ids
for way in newWays:
emplenarWay(wId,x) #Function that have to show the way in a map and alow the user to fill the form.
return render_to_response('principal/inici.html', context_instance = RequestContext(request)) #final template
def carregar_way(request, x, way_id):
if request.method=='POST':
formulari = WayForm(request.POST, request.FILES)
if formulari.is_valid():
x.processData(formulari.descripcio, formulari.tipus)
# something for render de form again or come back to the loop of the previous function... NO IDEA!!
else:
formulari = WayForm()
mapFeatures = x.getMapFeatures(way_id)
return render(request,'principal/WayForm.html',
{'formulari':formulari, 'mapFeatures'=mapFeatures})
表格.py
CHOICES = (('1','Pista',),('2','Corriol',))
class WayForm(forms.Form):
descripcio = forms.Textarea()
tipus = forms.ChoiceField(
widget=forms.RadioSelect, choices=CHOICES)
可能是这样的吗?