0

I'm using django-tables2 for a project. I want to create a new column which links to the admin page of that model so it can be edited. Can I do that?

user3080600
  • 1,309
  • 2
  • 11
  • 23
  • Does this question help? http://stackoverflow.com/questions/22941424/django-tables2-create-extra-column-with-links – Ben Apr 15 '17 at 21:14

1 Answers1

2

Yes, you can. The admin views have a fix naming scheme. The change view url of a specific instance can be reversed from 'admin:appname_modelname_change' and takes the instance's primary key as an argument:

from django_tables2.utils import A

column_name = tables.LinkColumn(
  viewname = 'admin:applabel_modelname_change', 
  args=[A('pk')],
  accessor=A('__str__')  # or whatever attribute of your instance you want to display
)
user2390182
  • 72,016
  • 6
  • 67
  • 89