Browse Source

Overload MemberAdmin to update inlines instead of monkey-patching

Grégoire Jadi 7 years ago
parent
commit
1cf6772200
1 changed files with 6 additions and 5 deletions
  1. 6 5
      hardware_provisioning/admin.py

+ 6 - 5
hardware_provisioning/admin.py

@@ -9,7 +9,7 @@ from django.forms import ModelChoiceField
 from django.utils import timezone
 
 from .models import ItemType, Item, Loan, Storage
-from coin.members.admin import MemberAdmin
+import coin.members.admin
 
 
 User = get_user_model()
@@ -181,7 +181,8 @@ class LoanInline(admin.TabularInline):
     def has_delete_permission(self, request, obj=None):
         return False
 
-# Avoid to add LoanInline twice in case the file is loaded more than
-# once.
-if LoanInline not in MemberAdmin.inlines:
-    MemberAdmin.inlines.append(LoanInline)
+class MemberAdmin(coin.members.admin.MemberAdmin):
+    inlines = coin.members.admin.MemberAdmin.inlines + [LoanInline]
+
+admin.site.unregister(coin.members.admin.Member)
+admin.site.register(coin.members.admin.Member, MemberAdmin)