From 1a565bacc7b6410f5e82b26e115a5a47952d7584 Mon Sep 17 00:00:00 2001 From: Mahal Date: Sat, 14 Oct 2023 00:18:59 +0200 Subject: [PATCH] Remove adding/editing/deleting abilities from the admin panel --- insalan/payment/admin.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/insalan/payment/admin.py b/insalan/payment/admin.py index 930f3456..2186b221 100644 --- a/insalan/payment/admin.py +++ b/insalan/payment/admin.py @@ -19,7 +19,10 @@ class ProductAdmin(admin.ModelAdmin): class TransactionAdmin(admin.ModelAdmin): - """Admin handler for Transactions""" + """ + Admin handler for Transactions + In the backoffice, Transactions can only be seen, they cannot be add, removed or changed this way + """ list_display = ( "id", @@ -38,12 +41,17 @@ class TransactionAdmin(admin.ModelAdmin): "last_modification_date", "amount", ] - readonly_fields = ["amount"] - - def save_model(self, request, obj, form, change): - """Save the model, recomputing the amount""" - obj.synchronize_amount() - super().save_model(request, obj, form, change) + def has_add_permission(self, request): + """Remove the ability to add a transaction from the backoffice """ + return False + + def has_change_permission(self, request, obj=None): + """ Remove the ability to edit a transaction from the backoffice """ + return False + + def has_delete_permission(self, request, obj=None): + """ Remove the ability to edit a transaction from the backoffice """ + return False admin.site.register(Transaction, TransactionAdmin)