diff --git a/rentals/models.py b/rentals/models.py index 2d7fec8..a63fabe 100644 --- a/rentals/models.py +++ b/rentals/models.py @@ -1,5 +1,9 @@ +from django.contrib import admin from django.core import validators from django.db import models, transaction +from django.db.models import F +from django.db.models.functions import Chr, Ord, Concat + from membershipworks.models import Member @@ -98,6 +102,17 @@ class LockerInfo(models.Model): return self.locker_unit.number_for_locker(self.column, self.row) @property + @admin.display( + description="Address", + ordering=Concat( + Chr(F("column") + Ord("locker_unit__first_letter")), + ( + F("row") + + F("locker_unit__first_number") + + (F("locker_unit__columns") - F("column") - 1) * F("locker_unit__rows") + ), + ), + ) def address(self) -> str: return f"{self.letter}{self.number}"