Disable "add rate" button in Admin interface (#5444)

- Does not work with custom backend
- Throws error if the button is pressed
- So, remove the button
This commit is contained in:
Oliver 2023-08-14 16:17:03 +10:00 committed by GitHub
parent 5731b88499
commit a2f614ad41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,10 @@
"""Admin classes"""
from django.contrib import admin
from django.http.request import HttpRequest
from djmoney.contrib.exchange.admin import RateAdmin
from djmoney.contrib.exchange.models import Rate
from import_export.resources import ModelResource
@ -43,3 +48,15 @@ class InvenTreeResource(ModelResource):
]
return [f for f in fields if f.column_name not in fields_to_exclude]
class CustomRateAdmin(RateAdmin):
"""Admin interface for the Rate class"""
def has_add_permission(self, request: HttpRequest) -> bool:
"""Disable the 'add' permission for Rate objects"""
return False
admin.site.unregister(Rate)
admin.site.register(Rate, CustomRateAdmin)