[Fixed]-How to prevent admin superusers from causing "Site matching query does not exist" errors?

1👍

Create a custom admin class like so:

class DeleteNotAllowedModelAdmin(admin.ModelAdmin):
    # Other stuff here
    def has_delete_permission(self, request, obj=None):
        return False

If you only want to prevent deletion of say the last site and allow when there are more than one defined in the database:

class DeleteNotAllowedModelAdmin(admin.ModelAdmin):
    # Other stuff here
    def has_delete_permission(self, request, obj=None):
        if Site.objects.count() > 1:
            return True
        return False

Or something like this.

Edit: and as for how to register that custom class, look here

Leave a comment