views:

109

answers:

2

I'm looking to add a method 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.

+2  A: 

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

D4V360
I'm not looking for that. Did you read my question? I already found that in here and on Django docs. I'm looking for a way to add a MODEL METHOD to the admin. Not a custom function.
orokusaki
You changed your question; And why don't you add a custom function that calls the model method? Does the same job I guess?
D4V360
+2  A: 

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.

Daniel Roseman
Thanks Daniel. That worked perfectly.
orokusaki