Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django: Hyperlink from Admin of Model to documentation

I have an application which uses the django admin interface extensively.

Some things in the admin GUI need explanations (domain/model specific docs).

We use sphinx and screenshots do explain details.

Is there a generic/automated way to create hyperlinks from the django admin interface of a model instance to the matching part in the docs?

I know that I could alter the admin templates of the models, but somehow I guess someone has a better idea how to solve this in a more professional way.

In my case the docs get hosted on the same server. AFAIK this is needed if you have the big dream, that there are links from the docs into the django application, too (but this is a different question).

What do I mean with "matching part in the docs"?

Imagine I have a model called "Foo".

And I have docs for the model (including images).

Now I would like to have a hyperlink from the admin page of the model to the docs for the model "Foo".

I think this is a very general issue. I think it is a pity that neither the framework nor a third party app help to write integrated docs.

like image 522
guettli Avatar asked Feb 03 '23 22:02

guettli


1 Answers

This is the method that I use to create links in the admin site for a particular model.

class YourModelAdmin(admin.ModelAdmin):

    def link_to_doc(self,obj):
        link = 'https://www.stackoverflow.com'
        return u'<a href="%s">%s</a>' % (link, "Link Name")

    link_to_doc.allow_tags = True
    link_to_doc.short_description = "Link Description for admin"

    fields = (
         'your_model_fields',
         'link_to_doc'           
    )

    readonly_fields = (
         'your_model_readonly_fields',
         'link_to_doc'           
    )


admin.site.register(YourModel, YourModelAdmin)
like image 89
Mehak Avatar answered Feb 15 '23 06:02

Mehak