From 5c92e5e8edf4ba4a7ed1e8516c822e48fb59e47b Mon Sep 17 00:00:00 2001 From: Charlie Prichard <46421052+CPrich905@users.noreply.github.com> Date: Mon, 13 Jan 2025 11:54:01 +0000 Subject: [PATCH] fix for measurement_unit_qualifier fields (#1383) --- quotas/forms/wizards.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/quotas/forms/wizards.py b/quotas/forms/wizards.py index 0efa9fa4a..f0b861cc4 100644 --- a/quotas/forms/wizards.py +++ b/quotas/forms/wizards.py @@ -292,6 +292,12 @@ def init_fields(self): self.fields["measurement_unit"].label_from_instance = ( lambda obj: f"{obj.code} - {obj.description}" ) + self.fields["measurement_unit_qualifier"].queryset = self.fields[ + "measurement_unit_qualifier" + ].queryset.order_by("code") + self.fields["measurement_unit_qualifier"].label_from_instance = ( + lambda obj: f"{obj.code} - {obj.description}" + ) self.fields["measurement_unit_qualifier"].help_text = ( "A measurement unit qualifier is not always required" ) @@ -559,6 +565,15 @@ def init_fields(self): if "description" in definition_data: fields["description"].initial = definition_data["description"] + self.fields["measurement_unit_qualifier"].help_text = ( + "A measurement unit qualifier is not always required" + ) + self.fields["measurement_unit_qualifier"].queryset = self.fields[ + "measurement_unit_qualifier" + ].queryset.order_by("code") + self.fields["measurement_unit_qualifier"].label_from_instance = ( + lambda obj: f"{obj.code} - {obj.description}" + ) if ( "measurement_unit_qualifier" in definition_data and definition_data["measurement_unit_qualifier"] != "None" @@ -576,9 +591,6 @@ def init_fields(self): definition_data["threshold"], ) fields["quota_critical"].initial = definition_data["quota_critical"] - self.fields["measurement_unit_qualifier"].help_text = ( - "A measurement unit qualifier is not always required" - ) def update_definition_data_in_session(self, cleaned_data): cleaned_data.update(