Search code examples
djangodjango-modelsdjango-extensions

How can I integrate autogenerated database model diagrams into admin documentation interface?


I'm using graph_models from django-extensions to generate diagrams from a Django application's database models. I would like to integrate the diagram into the documentation of the admin interface (django.contrib.admindocs). Is there a way to integrate the diagrams (preferably by executing a streamline command comparable to python manage.py collectstatic)?


Solution

  • I don't see why you can't. One potential way would be to create a management command that invokes the graph_models command with parameters such that the files are output into the STATIC_FILES directory (it might be the other static file setting).

    Then you can override whichever admin template you'd like to have the diagrams shown on. Perhaps including a link to the image of the diagram per table? I think that'd be django/contrib/admin/templates/admin/index.html.

    You'd need to define some naming convention that would be used in your management command as well as in the overriding admin template such that the images are rendered properly.

    In your deployment process, after calling collectstatic, you'd call the new management command.

    Again, this is one option. There are probably others.