Django - Adding model without default ModelAdmin permissions (add, change, delete, view)

Viewed 126

I am facing problems with adding simply new permission to admin panel
In my models.py i have:

class search_hostname(models.Model):
    class Meta:
        permissions = [("search_hostname", "Can search hostname")]

    def __str__(self):
        return self.application

but after makemigrations and migrate in my admin page i get "Can search hostname" and other four default:

app | search_hostname | Can add search_hostname
app | search_hostname | Can change search_hostname
app | search_hostname | Can delete search_hostname
app | search_hostname | Can view search_hostname
app | search_hostname | Can search hostname

i have no old migrations which would cause this
is there any way to avoud adding those default permissions and have only Can search hostname in DB

1 Answers

The attribute permissions [Django docs] is used for extra permissions on top of the default permissions that Django will make. If you don't want the default permissions or want to modify them, you need to set default_permissions [Django docs]:

class search_hostname(models.Model):
    class Meta:
        permissions = [("search_hostname", "Can search hostname")]
        default_permissions = []

    def __str__(self):
        return self.application
Related