[Answer]-Django – Add another model without Popup

1👍

Off the top of my head, you could use JS to grab the popup link and load the HTML in a div on the page. But that means you need to override the admin template. This QA should be helpful.

It also means you need to capture the saving of the new house. So, when someone presses save, depending on the response, the div either closes or shows the errors WITHOUT refreshing th page. I’m not sure but I think you’ll also need to override the admin view that does this to send back json responses.

OR

You could use JS to mute that link and call up your own url, which would allow you to create your own view with your own custom form that does this. This would give you a bit more control without having to hack away at the Admin functionality.

e.g /house/ajax_add

You’ll need to refresh the options in the House dropdown though. So I don’t think you can avoid extending the template, now that I think about it.

It seems like a lot of trouble, really. No magic way that I know of, but it’s possible.

👤onyeka

0👍

To avoid popups, you might want to look at https://github.com/FZambia/django-fm:

Django-fm allows to create AJAX forms for creating, editing, deleting
objects in Django. This is a very personalized approach to quickly
build admin-like interfaces.

A live example can be found on http://djangofm.herokuapp.com/.

I’m not sure how this integrates with the current admin site, but with some changes it should not be hard.

👤SaeX

Leave a comment