Reputation: 11561
Here's a piece of Django admin interface's instance edition form:
How should I change the underlying admin.ModelAdmin
instance to make it contain an URL, like this?
Upvotes: 2
Views: 1928
Reputation: 11760
Django makes this easy. Subclass ModelAdmin
, add a custom method and then tell the Admin how to use it. Here's a sample admin.py
:
from django.contrib import admin
from .models import Vendor
class VendorAdmin(admin.ModelAdmin):
readonly_fields = ['example_link']
def example_link(self, obj):
return '<a href="{}">link text</a>'.format(obj.get_link()) # however you generate the link
example_link.allow_tags = True
admin.site.register(Vendor, VendorAdmin)
Here's the documentation that furthers explains readonly_fields
, customizing the form label text with short_description
, ordering, and how you can put this custom url method on the Model
or ModelAdmin
.
Upvotes: 7