views:

105

answers:

1

I've managed to get Django Forms to dynamically generate additional fields based on the relationship between a specific instance (eg. 'product type') and another model (eg. 'product attributes') eg. products have common attributes like weight and price but a book has a page count and a computer has specs.

I'd like to be able to do the same with ModelForms so that I can just call form.save() but I'm not sure what the right approach would be to do this or where to start. At first I thought it would be possible by overriding some of the methods but then I've looked around the models.py file and it seems that I'd need to add quite a bit of code at various places in there to handle the additional fields ie. quite a lot of work. Or am I missing the easy way?

A: 

Without knowing the specifics, I'd say you're right. If the additional fields are not part of the model, then at the least, you'd have to override the ModelForm's save() method.

Rishabh Manocha