Search code examples
djangopython-3.xdjango-admindjango-tables2

Using Django admin site in other applications


My goal is to develop a web-application that would retrieve data from a database and display them in a table.

I'm new to the web-development, this task is not my main goal, therefore, I'd like to spend minimum efforts for it.

I've chosen Django for this task. I've got familiar with its admin site from the official tutorial, and can conclude that it has all required functionality (retrieving, sorting, filtering, search).

In parallel, I've installed django-tables2. It requires much more efforts, for example, writing CSS templates, while admin has all included.

Is it possible to use that admin site like ordinary web app just to display data, without adding or deletion?


Solution

  • Yes, you can do that. I have done it before. The challange is to create your target database structure. Django has an manage.py inspectdb command you can use to generate models from the target database. You would only need to override the ModelAdmin, so you cannot save it.

    class CustomAdmin(admin.ModelAdmin):
    
        def save_model(self, request, obj, form, change):
            pass