From 65d4381579a3448d3a906207ee74c44af9b86f4f Mon Sep 17 00:00:00 2001
From: Tore Brede <Tore.Brede@uib.no>
Date: Mon, 25 Apr 2022 14:16:09 +0200
Subject: [PATCH] GREG-247: Make the org unit list sorted alphabetically in the
 admin interface

---
 greg/admin.py  | 7 +++++--
 greg/models.py | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/greg/admin.py b/greg/admin.py
index 2d9252c4..41a54f00 100644
--- a/greg/admin.py
+++ b/greg/admin.py
@@ -123,10 +123,13 @@ class IdentifierAdmin(VersionAdmin):
 
 
 class OrganizationalUnitAdmin(VersionAdmin):
-    list_display = ("id", "name_en", "parent")
+    list_display = ("id", "name_en", "name_nb", "parent")
     readonly_fields = ("id", "created", "updated")
-    search_fields = ("name_en", "id")
+    search_fields = ("name_en", "name_nb", "id")
     inlines = (OuIdentifierInline,)
+    # This is mainly to make the org unit list be sorted in the drop-down box
+    # in the role line under persons
+    ordering = ('name_nb',)
 
 
 class OrganizationalUnitInline(admin.TabularInline):
diff --git a/greg/models.py b/greg/models.py
index 43fe9f07..349515c5 100644
--- a/greg/models.py
+++ b/greg/models.py
@@ -521,7 +521,7 @@ class OrganizationalUnit(BaseModel):
         )
 
     def __str__(self) -> str:
-        return f"{self.name_en or self.name_nb}"
+        return f"{self.name_nb} ({self.name_en})"
 
     def fetch_tree(self):
         """
-- 
GitLab