Parcourir la source

Overload MemberAdmin to update inlines instead of monkey-patching

Grégoire Jadi il y a 7 ans
Parent
commit
1cf6772200
1 fichiers modifiés avec 6 ajouts et 5 suppressions
  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)