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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---