Skip to content

Commit 5b05aa1

Browse files
committed
Add weight collection feature with metric/imperial support
1 parent 8e8942f commit 5b05aa1

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

lung_cancer_screening/questions/forms/metric_weight_form.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ def __init__(self, *args, **kwargs):
1818
'required': 'Enter your weight.',
1919
}
2020
)
21+
def clean_weight_metric(self):
22+
return self.cleaned_data['weight_metric'] * 10
2123

2224
class Meta:
2325
model = ResponseSet

lung_cancer_screening/questions/models/response_set.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ class ResponseSet(BaseModel):
4040
])
4141

4242
MIN_WEIGHT_METRIC = 254
43+
MAX_WEIGHT_METRIC = 3175
4344

4445
weight_metric = models.PositiveIntegerField(null=True, blank=True, validators=[
4546
MinValueValidator(MIN_WEIGHT_METRIC, message="Weight must be between 25.4kg and 317.5kg"),
46-
# MaxValueValidator(MAX_WEIGHT_METRIC, message="Height must be between 139.7cm and 243.8 cm"),
47+
MaxValueValidator(MAX_WEIGHT_METRIC, message="Weight must be between 25.4kg and 317.5kg"),
4748
])
4849

4950
submitted_at = models.DateTimeField(null=True, blank=True)
@@ -77,3 +78,12 @@ def formatted_height(self):
7778
value = Decimal(self.height_imperial)
7879
return f"{value // 12} feet {value % 12} inches"
7980

81+
@property
82+
def formatted_weight(self):
83+
if self.weight_metric:
84+
return f"{Decimal(self.weight_metric) / 10}kg"
85+
# elif self.height_imperial:
86+
# value = Decimal(self.weight_imperial)
87+
# return f"{value // 12} feet {value % 12} inches"
88+
89+

0 commit comments

Comments
 (0)