Order units by name

Issue #151 resolved
Wenze van Klink created an issue

I think it would me more logical to order the units by name then by number

Comments (3)

  1. Randle Taylor

    Hi Wenze,

    Our centre definitely wants things ordered by Unit number (we generally just refer to "Unit1" or "Unit 4" etc so in our case unit number is the natural ordering) but I think we can make this optional by having an ORDER_UNITS_BY = "name" # or "number" setting and then using that in the units.models.Unit ordering field and changing the following to lines in the ChooseUnit view:

            q = q.values("unit", "unit__type__name", "unit__name", "unit__number").order_by("unit__number").distinct()
    
            ordered = sorted(unit_types.items(), key=lambda x: min([u["unit__number"] for u in x[1]]))
    

    to something like:

            q = q.values(
                "unit", "unit__type__name", "unit__name", "unit__number"
            ).order_by(
                "unit__"+settings.ORDER_UNITS_BY
            ).distinct()
    
            ordered = sorted(unit_types.items(), key=lambda x: min([u["unit__"+settings.ORDER_UNITS_BY] for u in x[1]]))
    
  2. Log in to comment