two models -> one form -> addmanipulator
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 hope my question is not too stupid, but I'm still a django newbe. Thanks in advance! uli --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: two models -> one form -> addmanipulator
On 9/22/06, Ulrich Nitsche <[EMAIL PROTECTED]> 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 hope my question is not too stupid, but I'm still a django newbe. > > Thanks in advance! > > uli > No, I think you cann't do this in django. You should use custom manipulator for this. -- I like python! My Blog: http://www.donews.net/limodou UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad UliPad Maillist: http://groups.google.com/group/ulipad --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: two models -> one form -> addmanipulator
limodou schrieb: > No, I think you cann't do this in django. You should use custom > manipulator for this. Hmm, I think you could use it like this: ... form1 = forms.FormWrapper(manipulator1, data1, errors1) form2 = forms.FormWrapper(manipulator2, data2, errors2) return render_to_response(template, context_instance=RequestContext(request, "form1": form1, "form2": form2, ...)) I'm not sure if this works out, and how you'd separate request.POST into the two data dicts, and whether this is necessary at all. Perhaps it's a way. Though, I don't know if this is better than the other approach with the custom manipulator. It's an interesting question. Michael --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: two models -> one form -> addmanipulator
Once I used this kind of way and it really works. It's only kind of tricky to decide, when to call validators for each of the manipulators and when to save, if there is a relationship between the two models, for example: 1. if A and B are not saved, how to validate B, that has to be related to A, when A still has no primary key to assign to B. 2. should at first A be validated and saved, and only then B validated? If B is not valid, should A be deleted? As I've never used custom manipulators for this reason, it would be interesting to know is it easier to use the custom manipulator or this approach. Good luck! Aidas Bendoraitis [aka Archatas] On 9/22/06, Michael Radziej <[EMAIL PROTECTED]> wrote: > > limodou schrieb: > > No, I think you cann't do this in django. You should use custom > > manipulator for this. > > Hmm, I think you could use it like this: > > ... > form1 = forms.FormWrapper(manipulator1, data1, errors1) > form2 = forms.FormWrapper(manipulator2, data2, errors2) > return render_to_response(template, > context_instance=RequestContext(request, "form1": form1, > "form2": form2, ...)) > > > I'm not sure if this works out, and how you'd separate > request.POST into the two data dicts, and whether this is > necessary at all. Perhaps it's a way. > > Though, I don't know if this is better than the other approach > with the custom manipulator. It's an interesting question. > > Michael > > > > > --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: two models -> one form -> addmanipulator
On 9/22/06, Aidas Bendoraitis <[EMAIL PROTECTED]> wrote: > > Once I used this kind of way and it really works. It's only kind of > tricky to decide, when to call validators for each of the manipulators > and when to save, if there is a relationship between the two models, > for example: > 1. if A and B are not saved, how to validate B, that has to be related > to A, when A still has no primary key to assign to B. > 2. should at first A be validated and saved, and only then B > validated? If B is not valid, should A be deleted? > > As I've never used custom manipulators for this reason, it would be > interesting to know is it easier to use the custom manipulator or this > approach. > > Good luck! > Aidas Bendoraitis [aka Archatas] > Using custom manipulator is not because it's easier, just because many things that AddManipulator or ChangeManipulator couldn't do. Using custom manipulator you should write down which fields you want to process, and the fields are not the ModelField class but FormField class, so there are some differences between them and you should notice carefully. Then you also need to write your own save method to process the request data. So it's not easier, but I think it's more clearly, because you know what you'v done. And for complex situation, for example multi models need to be dealed at same time and they may have relationship also, so it's the only way to process for now I think. -- I like python! My Blog: http://www.donews.net/limodou UliPad Site: http://wiki.woodpecker.org.cn/moin/UliPad UliPad Maillist: http://groups.google.com/group/ulipad --~--~-~--~~~---~--~~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---
Re: two models -> one form -> addmanipulator
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 django-users@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users -~--~~~~--~~--~--~---