I'm looking to add a m开发者_如何学Pythonethod that my Ticket model has called process to the admin, so that I could click a link in the list view, and "process" my model instance (do an API call behind the scenes).
To clarify:
class Ticket(models.Model):
title = models.CharField(max_length=255)
def process(self):
... hardcore processing action ...
I need to add the process()
method directly to the admin without using a separate function.
You just need to provide a small method in your ModelAdmin class that returns a link pointing at a view that calls your model method, and add the name of that method to the modeladmin's list_display
tuple. You'll obviously also need to define this view itself, and a url that points to it.
Yes, thats possible; Check out this documentation, just what you need:
http://docs.djangoproject.com/en/1.1/ref/contrib/admin/actions/#ref-contrib-admin-actions
精彩评论