Skip to content

Commit

Permalink
Disable "add rate" button in Admin interface (#5444) (#5447)
Browse files Browse the repository at this point in the history
- Does not work with custom backend
- Throws error if the button is pressed
- So, remove the button

(cherry picked from commit a2f614a)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
  • Loading branch information
github-actions[bot] and SchrodingersGat committed Aug 14, 2023
1 parent b8e726d commit 89d8e47
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions InvenTree/InvenTree/admin.py
@@ -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


Expand Down Expand Up @@ -43,3 +48,15 @@ def get_fields(self, **kwargs):
]

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)

0 comments on commit 89d8e47

Please sign in to comment.