Question: I'm developing a Ticket system. Each ticket can be assigned to a user.
On the ticket list\_display in django-admin I want to have a column that either displays the user assigned to that ticket, or a link 'Assign ticket to myself'. I know I could use list\_editable or make a custom action to do this, but for usability reasons I want a link in the list\_display.

models.py

```
class Ticket(models.Model):
    assigned = models.ForeignKey(User, null=True)

    def assigned_to(self):
        if self.assigned:
            return self.assigned
        else:
            return "<a href="link/to/something/">Assign ticket to myself</a>"
    assigned_to.allow_tags = True

    # untested example method for assigning user to a ticket
    def assign(self, user):
        self.assigned = user
        self.save()

```

This is where I got stuck. 

I need that the user can click on the link, which will call the model method assign() to assign the user to the ticket, and reloads the page so the username is displayed in the list\_display.

I hope someone can help me in the right direction. Note that I'm just a Django beginner...

Answer: 
Alternatively, something like this should work:

```
from django.contrib import admin, messages
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.utils.translation import ugettext_lazy as _

class TicketAdmin(admin.ModelAdmin):
    list_display = ('__str__', 'make_mine_link',)  

    def get_urls(self):
        urls = super(TicketAdmin, self).get_urls()
        opts = self.model._meta

        my_urls = patterns('',
            (r'^([0-9]+)/assign-to-me/$',
                self.admin_site.admin_view(self.make_mine), 
                name='%s_%s_make_mine' % (opts.app_label, opts.model_name)),
        )
        return my_urls + urls

    def make_mine(self, request, object_id):
        opts = self.model._meta
        redirect_to = reverse('admin:%s_%s_changelist' % (
            opts.app_label, opts.model_name), current_app=self.admin_site.name)
        ticket = get_object_or_404(self.model, pk=object_id)

        ticket.assigned = request.user
        ticket.save()

        msg = _('The selected Ticket now belong to you.')
        self.message_user(request, msg, messages.SUCCESS)
        return HttpResponseRedirect(redirect_to)

    def make_mine_link(self, obj):
        opts = self.model._meta
        url = reverse('admin:%s_%s_make_mine' % (opts.app_label, opts.model_name), args=(obj.pk,), )
        return '<a href="%s">Assign ticket to myself</a>' % url
    make_mine_link.allow_tags = True

admin.site.register(Ticket, TicketAdmin) 

```

I haven't tested this. If you have any issue, feel free to add a comment.
Have you considered using custom admin actions?

```
class TicketAdmin(admin.ModelAdmin):

    actions = [make_mine]

    def make_mine(self, request, queryset):
        """
        Set the Ticket to the current user.
        """
        for ticket in queryset:
            ticket.assigned = request.user
            ticket.save()
        self.message_user(request, _('The selected Ticket now belong to you.'))
    make_mine.short_description = _('Set the Ticket to the user')

```

Docs: <https://docs.djangoproject.com/en/1.8/ref/contrib/admin/actions/>