3

I have a django admin view displaying a list of orders. I have added a custom button, which when clicked should perform a certain action.

enter image description here

So I have a function defined in my services.py file as :

def penalty(order):
  #Do something

So, how should I call this function when Penalty is clicked. I can create a view, but how to call it?

Paras
  • 3,191
  • 6
  • 41
  • 77

3 Answers3

3

All u need is here:

https://medium.com/@hakibenita/how-to-add-custom-action-buttons-to-django-admin-8d266f5b0d41

Follow the easy steps and your ready to go. Many others all around the web.

Ohad the Lad
  • 1,889
  • 1
  • 15
  • 24
1

The following answers could be helpful for solving your problems.

Kushan Gunasekera
  • 7,268
  • 6
  • 44
  • 58
0

You can add a URL like this to call a function

     def get_urls(self):
        urls = super().get_urls()
        custom_urls = [
            path(
                'penalty/<int:id>',
                self.admin_site.admin_view(self.penalty),
                name='penalty'
            )
        ]
        return custom_urls + urls

from a button click in Django admin

omkar yadav
  • 177
  • 5
  • 15