HI , I have a template which consist of fields in a master table and a foreign key table. i want user fill the foreign key field data inline in 1 template.
and when use submit it, new data of course, i need the data to saved in the master table, then save the foreign table with the foreignkey of the master table id just inserted. after some search and test i finaly get it, but need opinion is this the best way to do this ? here are the view code ;: def myadmin_new_flat_page(request, template_name="myadmin/change_data.html"): if request.method == 'POST': # If the form has been submitted... form = AdminFlatPageModelForm(request.POST) # A form bound to the POST data inlineform = AdminFlatPageMetaModelForm(request.POST) # A form inline postdata = request.POST.copy() if form.is_valid(): # All validation rules pass fp = form.save(commit=True) fp.save() key= request.POST.get('flatpage','nothing') postdata['flatpage']=int(fp.pk) key = str(request.POST) a=str(postdata) data={'flatpage_id':int(fp.pk),'keyword':'finest code','description':'interested ? ' } w='not' inlineform=AdminFlatPageMetaModelForm(initial=data) # this not work ? if not inlineform.is_valid(): ifp = inlineform.save(commit=False) w='work' ifp.flatpage_id=fp.pk ifp.keyword = request.POST.get('keyword') ifp.description = request.POST.get('description') ifp.save() messages.success(request, 'New '+ me +' Added' + str(fp.pk) + key + a+w) redirect=False return render_to_response('myadmin/please_wait.html',locals(),context_instance = RequestContext(request) ) else: form = AdminFlatPageModelForm() inlineform = AdminFlatPageMetaModelForm() button = _generate_button('new') return render_to_response(template_name,locals(),context_instance = RequestContext(request) ) i get manage to save the foreign table with manual assigning the fields. then save it. thanks before. Mulianto -- 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.