2009/10/16 Luke Sneeringer <[email protected]>:
>
> Good morning,
> I have two models that have mostly-similar fields (they both inherit
> from a single, abstract model in Django) and one different field. I'd
> really like it to be two separate tables in the database for
> normalization (each has a separate, one-to-many relationship with
> another table and the two are of distinct type and do not intersect).
>
> However, I would like to make a form that will seamlessly create (or
> edit) a row in one of these two tables. So, at first I set out to make
> a generic form (extending django.forms.Form) that displayed the
> fields, as well as a "type" ChoiceField that determined whether to
> save an instance of the first model or the second. Then, for editing,
> I simply have straight, unrelated django.forms.ModelForm classes that
> are instantiated.

You can create a factory for the form. That is, given the information
from the html, you choose wicht form to instantiate.

def get_form(param):
  if param == 'op1':
     return Form1
  elif param =='op2':
    return Form2
...

On the view file

MyForm = get_form(param_from_request)

Form1 and Form2 are Modelforms


-- 
Antoni Aloy López
Blog: http://trespams.com
Site: http://apsl.net

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to