0👍
✅
Finally I’m using a modified https://django-salmonella.readthedocs.org/en/latest/. I don’t show the input field and show the selected records in a table.
0👍
-
It’s possible. In order to select more than one record, you need to override default
dismissRelatedLookupPopup()
indjango/contrib/admin/static/admin/js/admin/RelatedObjectLookups.js
by including your script in theMedia
class of yourModelAdmin
or widget:var dismissRelatedLookupPopup = (function(prev, $) { return function(win, chosenId) { var name = windowname_to_id(win.name); var elem = document.getElementById(name); // 1. you could add extra condition checking here, for example if ($(elem).hasClass('my_raw_id_ext_cls')) { // add this class to the field // ...logic of inserting picked items from the popup page } else { // default logic prev(win, chosenId); } // 2. or you could copy the following part from RelatedObjectLookups.js ... if (elem.className.indexOf('vManyToManyRawIdAdminField') != -1 && elem.value) { elem.value += ',' + chosenId; // 2. and add a return. Remember this acts globally. return; } else { document.getElementById(name).value = chosenId; } // 3. the following line cause the popup to be closed while one item is picked. // You could comment it out, but this would also affect the behavior of picking FK items. win.close(); } })(dismissRelatedLookupPopup, django.jQuery);
-
Django does not support this by default. There are some snippets at djangosnippets.org, you may want to take a look at them.
👤okm
- [Django]-Return object when aggregating grouped fields in Django
- [Django]-Renderer returned unicode, and did not specify a charset value
- [Django]-Override Django User Manager to only return active users in queries
Source:stackexchange.com