Thanks for the offer. I have altered the function as suggested: def property_data(request, property_id='0'): message = '' st = request.session['street_id'] print "At start of property_data, request.method=", request.method print "At start of property_data, st=", st if request.method == "POST": form = PropertyForm(request.POST) form['street']=request.session['street_id'] print "form=", form if form.is_valid(): form.save() message='we are added' return HttpResponseRedirect('somewhere')
And here is the traceback: Environment: Request Method: POST Request URL: http://localhost:8000/wha/address/1/add_property/ Django Version: 1.0.2 final Python Version: 2.5.1 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.admin', 'django.contrib.auth', 'whasite.wha'] Installed Middleware: ('django.middleware.common.CommonMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware') Traceback: File "/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/ site-packages/django/core/handlers/base.py" in get_response 86. response = callback(request, *callback_args, **callback_kwargs) File "/Users/michael/Documents/Django Projects/whasite/../whasite/wha/ data.py" in property_data 35. form['street']=request.session['street_id'] Exception Type: TypeError at /wha/address/1/add_property/ Exception Value: 'PropertyForm' object does not support item assignment On Jun 5, 5:15 pm, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On Jun 5, 5:33 am, adelaide_mike <mike.ro...@internode.on.net> wrote: > > > > > Another "in principle" question. My Street model is the parent of my > > Property model, many to one via foreign key. > > > User selects the street and I store it in request.session. User then > > gets to enter the property details in this form: > > > class PropertyForm(ModelForm): > > class Meta: > > model = Property > > exclude = ('street', 'price1', 'price2',) > > > and when the Add is clicked we do: > > > def property_data(request, property_id='0'): > > st = request.session['street_id'] > > print "At start of property_data, st=", st # debug, so I > > know it has the correct value > > if request.method == "POST": > > if property_id > '0': > > #do something > > else: > > form = PropertyForm(request.POST) > > form['street']=request.session['street_id'] > > if form.is_valid(): > > try: > > form.save() > > return > > HttpResponseRedirect('somewhere') > > except: > > message='database error in ADD' > > #debug, this is returned > > to the page > > Because all fields in property (except the foreign key street) either > > have data or are blank=True, the problem must? be the lack of the > > foreign key. (In admin I can add propertys). How do I get it into the > > data to be saved? > > > Mike > > Don't guess. Look at what the traceback actually says. Especially, > don't use a raw 'except', as that will swallow all types of errors. > Leave out the try/except for now, and let Django print the traceback > page, then show us what it says. > -- > DR. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---