开发者

Is it possible for Django ModelForms to work with dynamically added fields?

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 pl开发者_开发百科aces in there to handle the additional fields ie. quite a lot of work. Or am I missing the easy way?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜