Ability to change dismissRelatedLookupPopup on my own callback function

207 views
Skip to first unread message

Alex Kamedov

unread,
Jun 13, 2011, 12:16:11 AM6/13/11
to Django developers
Hi all!

I make integration with warehouse system and want to reuse existing functionality in django.contrib.admin to manage links between this system and catalog on site.
I can't get access to warehouse system database, I have only export file. I write some views to represent its items in django admin. And now I need something like related field in django admin forms, but has some filters applied to changelist and has some other user interface.

I think, the best solution for this case is put some links with showRelatedObjectLookupPopup javascript function on admin changelist, but after user choose the object, my own javascript function must be called instead of dismissRelatedLookupPopup javascript function.

Execution of dismissRelatedLookupPopup is hard coded in python code now. The easiest way to implement use case described higher is adding new GET argument "_callback" to changelist view.

What are you think about this? If this solution was accepted I can write patch and tests for it.

Cheers!
--
Alex Kamedov
skype: kamedov    www: kamedov.ru

Harris Lapiroff

unread,
Jun 13, 2011, 10:23:51 AM6/13/11
to Django developers
I think this is a great idea! I would certainly benefit from it.

It might be worth considering if there are any methods for passing a
callback function that are better than GET parameters—though I can't
think of any off the top of my head.

H.

Alex Kamedov

unread,
Jun 13, 2011, 11:57:05 PM6/13/11
to django-d...@googlegroups.com
It might be worth considering if there are any methods for passing a
callback function that are better than GET parameters—though I can't
think of any off the top of my head.

I can't provide better solution too. 

I look at the django.contrib.admin source. This can be applied only if 'pop' argument exists in GET parameters for changelist and  '_popup' argument exists in GET parameters for adding new item. The changes will be affect to methods are listed below:
  • django.contrib.admin.options.ModelAdmin.response_add
  • django.contrib.admin.templatetags.admin_list.items_for_result
  • django.contrib.admin.views.main.ChangeList.__init__


Cheers!

Gregor Müllegger

unread,
Jun 14, 2011, 6:29:12 AM6/14/11
to django-d...@googlegroups.com
Hi I needed to do the same in my own projects, however I just
decorated the functions which I wanted to modify. Like:

original_dismissRelatedLookupPopup = window.dismissRelatedLookupPopup;
window.dismissRelatedLookupPopup = function () {
// put your own code here ...
original_dismissRelatedLookupPopup.apply(this, arguments);
};

Maybe this helps until a way is introduced in django to modify this behaviour.

--
Servus,
Gregor Müllegger

> --
> You received this message because you are subscribed to the Google Groups "Django developers" group.
> To post to this group, send email to django-d...@googlegroups.com.
> To unsubscribe from this group, send email to django-develop...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/django-developers?hl=en.
>

Alex Kamedov

unread,
Jun 14, 2011, 7:18:53 AM6/14/11
to django-d...@googlegroups.com
Thank you for sharing good solution, Gregor!
Your solution works great if you has one related lookup. If you need work with some related fields you must write more javascript code whitch looks like mankey patching.

Alex Kamedov

unread,
Jun 14, 2011, 9:43:15 PM6/14/11
to django-d...@googlegroups.com
I create ticket and upload patch.
Reply all
Reply to author
Forward
0 new messages