Django: Admin inline forms initial data for every instance

前端 未结 6 1545
名媛妹妹
名媛妹妹 2020-12-15 05:20

I\'ve been reading a lot but I don\'t seem to be able to figure out a solution to this.

I\'m writing an application in Django, I\'m still writing the admin side.

6条回答
  •  感动是毒
    2020-12-15 06:00

    I realized that I solved the problem myself and hadn't answered here.

    What I finally did is to override the Environment class save_model method instead for using the admin forms.

    I'll explain a little bit better:

    I have an environment object and a server object. An environment has a number of servers that are linked to it via a foreign key into the server object. My goal was to populate the servers associated to an environment in the environment creation process. To be able to do that what I did was override the save_model method for the Environment object, do an obj.save() and AFTERWARDS create the Server objects that point to this environment, and then obj.save() again. Why afterwards? Because I can't relation a new created server with an environment that doesn't exist yet. Let me know if there is someone interested on he actual code.

提交回复
热议问题