Skip to content

Commit

Permalink
Remove adding/editing/deleting abilities from the admin panel
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiroUsagi-san committed Oct 13, 2023
1 parent fb404d3 commit 1a565ba
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions insalan/payment/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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)

0 comments on commit 1a565ba

Please sign in to comment.