0

Is there any magic why to do this in admin panel of django? enter image description here

Let me know

beddamadre
  • 1,583
  • 2
  • 19
  • 40
  • Well, if the form doesn't show in a popup, where/how do you want it to show? – onyeka Apr 10 '15 at 11:18
  • You can override the admin template to link to the actual add page for the house model. But then the user would lose the data already entered and would have to go back to the original model. Maybe you'd want a modal instead? – dan-klasson Apr 10 '15 at 11:27
  • @onyeka I'd like to innestate the house form inside the actual form with JS - duable, easy? – beddamadre Apr 10 '15 at 11:46
  • 1
    @beddamadre Oh okay the word 'innestate' confused me. I think it's doable. Not so sure about the easy part :). – onyeka Apr 10 '15 at 12:07

2 Answers2

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.

Community
  • 1
  • 1
onyeka
  • 1,517
  • 13
  • 18
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
  • 17,240
  • 16
  • 77
  • 97