开发者

Django inline formset with child of a child

开发者 https://www.devze.com 2023-01-05 10:44 出处:网络
I have three models: Variable, which has Group as a foreign key Group, which has Set as a foreign key Set

I have three models:

  1. Variable, which has Group as a foreign key
  2. Group, which has Set as a foreign key
  3. Set

I want to create a form that lets user create a new Set based on existing Set. Only things that user is able to modify are the Set name and Variable values.

This has given me an idea of using inlineformset_factory to access models' children. Sadly, all the examples I found go only one layer down.

Is there any way to access the Variables of a Set through inlineformset_factory?

If not - what is a good wa开发者_运维百科y to accomplish my goal?

Thank you.


From my experience, it is not worth hacking the existing inlineformset_factory to achieve much beyond what it is meant to do.

You are better off writing a custom view with the qs you want to use and create unique ids for each form element, to identify its parent.

0

精彩评论

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