0

I want to replicate the green plus from the admin site in my own app to add a record to a table. I have it mostly working (using mainly this: Django admin - How can I add the green plus sign for Many-to-many Field in custom admin form), except that instead of a pop-up window, the add page loads in the same window and does not disappear when I click 'save'.

The following html is generated by my app, which appears OK (the onclick bit):

<a href="/admin/pricemanager/item/add/" class="add-another" id="add_id_form-0-item" onclick="return showAddAnotherPopup(this);">

But it appears that some javascript is missing at the top of the page. Am I forgetting to include something in my template?

I have found some related questions such as Django Admin popup functionality, but I don't understand the answers.

How can I make the pop-up work? (I would think that it should not be necessary to write lots of custom javascript - of which I know nothing - to make something work that already works in the admin app)

Community
  • 1
  • 1
John Peters
  • 1,177
  • 14
  • 24
  • You would be missing `showAddAnotherPopup` function which is defined in _RelatedObjectLookups.js_ which shows a popup. Probably you would also need `dismissAddAnotherPopup`. – Rohan Aug 22 '12 at 05:46
  • @Rohan: where do I find those and how/where do I insert/include them? – John Peters Aug 22 '12 at 05:51

1 Answers1

0

You need to include following in your template to load admin related JS.

<script type="text/javascript" src="/admin/jsi18n/"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/core.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/admin/RelatedObjectLookups.js"> </script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.js"></script>
<script type="text/javascript" src="{{ STATIC_URL }}admin/js/jquery.init.js"></script>

This is with reference to answers for Using Django time/date widgets in custom form

Community
  • 1
  • 1
Rohan
  • 52,392
  • 12
  • 90
  • 87