python - Django ChainedForeignKey smart menu -
i trying make chained select menu, have model:
from django.db import models class health_plan(models.model): name = models.charfield(max_length=15) class doctors_list(models.model): name = models.charfield(max_length=30) specialty = models.charfield(max_length=15) health_plans = models.manytomanyfield(health_plan, related_name="doctors") location = models.charfield(max_length=15) def __unicode__(self): return self.name
and forms.py
:
class specform(modelform): = doctors_list.objects.values_list('specialty', flat=true) unique = [('---------------','---------------')] + [(i,i) in set(a)] specialty = forms.choicefield(choices=unique) class meta: model = doctors_list class healthform(modelform): hplan = chainedforeignkey( health_plan, chained_field="specialty", chained_model_field="specialty", show_all=false, auto_choose=true )
my urls.py
:
from django.conf.urls import patterns, include, url testapp.views import spec_form testapp.views import health_form django.contrib import admin admin.autodiscover() urlpatterns = patterns('', # examples: url(r'^$', 'medbook.views.home', name='home'), # url(r'^medbook/', include('medbook.foo.urls')), url(r'^admin/doc/', include('django.contrib.admindocs.urls')), url(r'^admin/', include(admin.site.urls)), url(r'^hello/$', spec_form, health_form), )
and views.py
:
from django.shortcuts import render_to_response testapp.forms import specform testapp.forms import healthform def spec_form (request): if request.method == 'post': form = specform(request.post) if form.is_valid(): form.save() else: form = specform() return render_to_response('hello.html', {'form':form}) def health_form (request): if request.method == 'post': form = healthform(request.post) if form.is_valid(): form.save() else: form = specform() return render_to_response('hello.html', {'form':form})
by error 'function' object not iterable
when acess webpage. new django , find tricky. user must select 1 specialty, , should appear health_plans cover specialty.
the health_plans have manytomany relationship doctors. when person chooses specialty, script should check wich doctors belong specialty , retrieve health plans hold doctors.
i hope made clear, code isn't.
any kindly appreciated
edit: stack trace
internal server error: /hello/ traceback (most recent call last): file "c:\python27\lib\site-packages\django\core\handlers\base.py", line 103, in get_response resolver_match = resolver.resolve(request.path_info) file "c:\python27\lib\site-packages\django\core\urlresolvers.py", line 321, in resolve sub_match = pattern.resolve(new_path) file "c:\python27\lib\site-packages\django\core\urlresolvers.py", line 221, in resolve kwargs.update(self.default_args) typeerror: 'function' object not iterable [08/may/2013 19:30:45] "get /hello/ http/1.1" 500 62490
change:
url(r'^hello/$', spec_form, health_form)
url(r'^hello/$', spec_form)
also, in models:
class health_plan(models.model): name = models.charfield(max_length=15) def __unicode__(self): return "%s"%(self.name)
Comments
Post a Comment