Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 623
nemesisdesign Avatar asked Dec 28 '11 23:12

nemesisdesign


People also ask

How can I remove extra's from Django admin panel?

You can add another class called Meta in your model to specify plural display name. For example, if the model's name is Category , the admin displays Categorys , but by adding the Meta class, we can change it to Categories . Literally saved my life!

How do I restrict access to parts of Django admin?

Django admin allows access to users marked as is_staff=True . To disable a user from being able to access the admin, you should set is_staff=False . This holds true even if the user is a superuser. is_superuser=True .

How do I override a Django form?

You can override forms for django's built-in admin by setting form attribute of ModelAdmin to your own form class. See: https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.form.


2 Answers

Django 2.0 above you can add in default admin

admin.site.site_url = None

Above trick worked for me very well.

like image 161
Hardik Gajjar Avatar answered Oct 26 '22 08:10

Hardik Gajjar


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)
like image 20
pragmar Avatar answered Oct 26 '22 07:10

pragmar