Search code examples
pythondjangodjango-admindjango-authentication

Django: Remove "view on site" button in the admin User change form


get_absolute_url() method is cool, but in some cases is not needed. django.contrib.auth.models.User has it set by default, this cause my projects to have a broken link in the admin.

How can I prevent that from happening?

In one of my old projects I set a custom template in which I removed the html of the button, it doesn't sound like a good solution that would scale though. Anything better?


Solution

  • This can be done, per model, as of django 1.7.

    # myapp/admin.py
    from django.contrib import admin
    from myapp.models import MyModel
    
    class MyModelAdmin(admin.ModelAdmin):
        view_on_site = False
    
    admin.site.register(MyModel,MyModelAdmin)