Ulrich Nitsche wrote:
> hi,
>
> i have two models (tables) concerning user data which belong together.
> Now I would like to use one single form to display and edit these
> values.
> Is there a way to use one changemanipulator to do this?
> Or if this is not possible is there a way to use different
> changemanipulators at the same
> time?
> How would this look like?
I'm doing something similar. I have a financial instrument object that
is split into two tables: Inst and InstDetail. But I want them to
appear as parts of the same object. My situation is slightly more
complicated in that each Inst has two InstDetails objects - a default
and an override. The user can only edit the override part. Here's how
my update view looks:
def update_inst(request, inst_id):
inst_manip = Inst.ChangeManipulator(inst_id)
inst = inst_manip.original_object
default = InstDetail.objects.get(inst=inst, is_override=False)
detail = InstDetail.objects.get(inst=inst, is_override=True)
detail_manip = InstDetail.ChangeManipulator(
detail.id,
follow={'is_override': False})
detail_manip.default_object = default
if request.POST:
new_data = request.POST.copy()
# fk's are not fixed up??
new_data['inst_id'] = inst.id
new_data['inst'] = inst.id
errors = {}
errors.update(inst_manip.get_validation_errors(new_data))
errors.update(detail_manip.get_validation_errors(new_data))
inst_manip.do_html2python(new_data)
detail_manip.do_html2python(new_data)
if not errors:
inst_manip.save(new_data)
detail_manip.save(new_data)
return HttpResponseRedirect(inst.get_absolute_url())
print errors
else:
errors = {}
new_data = {}
new_data.update(inst_manip.flatten_data())
new_data.update(detail_manip.flatten_data())
inst_form = forms.FormWrapper(inst_manip, new_data, errors)
detail_form = forms.FormWrapper(detail_manip, new_data, errors)
return render_to_response('core/inst_form.html',
{ 'inst_form': inst_form,
'detail_form': detail_form })
Note that I use the Inst id to find the corresponding InstDetail
objects and then create both manipulators. The rest is just standard
update logic but repeated twice. Then I return both forms to the
template. Its been working fine so far.
-Dave
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---