[rentals] Allow sorting LockerInfos by address
This commit is contained in:
parent
3b8d97573f
commit
81377a8a87
@ -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}"
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user