Populating django admin inline fields with javascript

103 views
Skip to first unread message

Mario Sassmann

unread,
Jul 16, 2019, 3:49:10 PM7/16/19
to Django users

Hi!

I'm trying to write an importer for populating admin model fields with existing model data: This is my approach: I modified the admin view for the specific model and added a form including select boxes to choose the existing model and a button to start the import.

As I'm using drf for many other stuff I wrote an endpoint which delivers the model data via get request. When clicking the button some javascript logic is populating the fields with the given data.

For inline models I'm triggering a 'click' to add the necessary rows before filling the fields.

This is working as expected. But after clicking the save button, the classic error

please correct the errors below

appears.

After implementing some logging, I could figure out the actual error message which is related to the the inline model fields.

The inline value did not match the parent instance.

Is django doing some other "magic" I'm missing when filling the inline admin fields?

Thanks in advance


Mario Sassmann

unread,
Jul 16, 2019, 3:54:49 PM7/16/19
to Django users

OK I solved the problem. I accidently set the primary keys (hidden fields) when populating the inline forms with javascript.

Reply all
Reply to author
Forward
0 new messages