Parcourir la source

lien vers adhésion

Élie Bouttier il y a 8 ans
Parent
commit
25bceeddb3
2 fichiers modifiés avec 17 ajouts et 13 suppressions
  1. 12 12
      adhesions/admin.py
  2. 5 1
      adhesions/models.py

+ 12 - 12
adhesions/admin.py

@@ -70,14 +70,14 @@ class UserIsAdherentFilter(admin.SimpleListFilter):
 
 
 class UserAdmin(AuthUserAdmin):
-    list_display = AuthUserAdmin.list_display + ('adherent_id',)
+    list_display = AuthUserAdmin.list_display + ('get_adhesion_link',)
     list_filter = (AuthUserAdmin.list_filter[2], UserIsAdherentFilter) # [2] = actif
 
-    def adherent_id(self, user):
-        adherent = user.adhesion
-        if adherent:
-            return adherent.id
-    adherent_id.short_description = 'Numéro d’adhérent'
+    def get_adhesion_link(self, user):
+        adhesion = user.adhesion
+        if adhesion:
+            return adhesion.get_adhesion_link()
+    get_adhesion_link.short_description = 'Numéro d’adhérent'
 
     def get_form(self, request, obj=None, **kwargs):
         if obj:
@@ -179,16 +179,16 @@ class AdhesionAdmin(admin.ModelAdmin):
 
 
 class CorporationAdmin(admin.ModelAdmin):
-    list_display = ('social_reason', 'adherent_id')
+    list_display = ('social_reason', 'get_adhesion_link')
     inlines = (AdhesionInline,)
     search_fields = ('social_reason',)
     filter_horizontal = ('members',)
 
-    def adherent_id(self, corporation):
-        adherent = corporation.adhesion
-        if adherent:
-            return adherent.id
-    adherent_id.short_description = 'Numéro d’adhérent'
+    def get_adhesion_link(self, corp):
+        adhesion = corp.adhesion
+        if adhesion:
+            return adhesion.get_adhesion_link()
+    get_adhesion_link.short_description = 'Numéro d’adhérent'
 
     def get_actions(self, request):
         actions = super().get_actions(request)

+ 5 - 1
adhesions/models.py

@@ -62,9 +62,13 @@ class Adhesion(models.Model):
 
     def get_adherent_link(self):
         url = reverse('admin:adhesions_%s_change' % self.adherent._meta.model_name, args=(self.adherent.id,))
-        return format_html(u'<a href="{}">{}</a>', url, str(self.adherent))
+        return format_html(u'<a href="{}">{}</a>', url, self.get_adherent_name())
     get_adherent_link.short_description = 'Nom ou raison sociale'
 
+    def get_adhesion_link(self):
+        url = reverse('admin:adhesions_adhesion_change', args=(self.id,))
+        return format_html(u'<a href="{}">ADT{}</a>', url, str(self.id))
+
     def __str__(self):
         return 'ADT%d' % self.id
         if self.id is None: