Browse Source

color in admin

boyska 4 years ago
parent
commit
5a4ead46c9
2 changed files with 9 additions and 4 deletions
  1. 8 3
      rxmap/rxmapp/admin.py
  2. 1 1
      rxmap/rxmapp/models.py

+ 8 - 3
rxmap/rxmapp/admin.py

@@ -10,9 +10,14 @@ admin.site.register(TipoRadio)
 class UserAdmin(auth.admin.UserAdmin):
     pass
 
-
+from django.utils.html import format_html
 @admin.register(RapportoRicezione)
 class RapportoAdmin(admin.ModelAdmin):
-    list_display = ('id', 'indirizzo', 'created', 'author')
-    list_filter = ('author', 'created')
+    # TODO: comprensibile dovrebbe essere un pallino colorato
+    list_display = ('id', 'indirizzo', 'color_circle', 'created', 'author')
+    list_filter = ('author', 'created', 'comprensibile')
     search_fields = ('indirizzo',)
+    def color_circle(self, x):
+        return format_html('<span style="color: {}">&#9679;</span>', x.colore)
+    color_circle.allow_tags = True
+    color_circle.description = 'Comprensibilità'

+ 1 - 1
rxmap/rxmapp/models.py

@@ -56,7 +56,7 @@ class RapportoRicezione(models.Model):
 
     @property
     def colore(self):
-        colors = ["darkred", "red", "yellow", "orange", "#90c90d", "green"]
+        colors = ["darkred", "red", "orange", "yellow", "#90c90d", "green"]
         c = int(self.comprensibile)
         return colors[c]