morlandi / django-ajax-datatable

A Django app which provides the integration of a Django project with the jQuery Javascript library DataTables.net
MIT License
215 stars 65 forks source link

Add hyperlink to Django Admin Change form #100

Closed michaeldacanay closed 1 year ago

michaeldacanay commented 1 year ago

Is it possible to add a hyperlink to the Change form of a model in Django admin? For example, if there is mymodel column, clicking the name in a row will direct to the Change mymodel form for that model.

morlandi commented 1 year ago

You can do it with customize_row() as shown here:

https://github.com/morlandi/django-ajax-datatable#customize-row

michaeldacanay commented 1 year ago

Thanks! I just added this to the AjaxDatatableView-derived view, where mymodelname is the displayed column value for mymodel model:

def customize_row(self, row, obj):
    row['mymodelname'] = '<a href="%s">%s</a>' % (
        reverse('admin:myapp_mymodel_change', args=(obj.id,)),
        obj.mymodelname
    )
    return