1010
1111"""
1212import logging
13+ from decimal import Decimal
1314from uuid import uuid4
1415
16+ from django .core .validators import MinValueValidator
1517from django .db import models , DatabaseError
1618from django .db .models .signals import post_save
1719from django .dispatch import receiver , Signal
@@ -177,8 +179,18 @@ class Score(models.Model):
177179 """
178180 student_item = models .ForeignKey (StudentItem )
179181 submission = models .ForeignKey (Submission , null = True )
180- points_earned = models .PositiveIntegerField (default = 0 )
181- points_possible = models .PositiveIntegerField (default = 0 )
182+ points_earned = models .DecimalField (
183+ decimal_places = 2 ,
184+ default = Decimal ('0.0' ),
185+ max_digits = 6 ,
186+ validators = [MinValueValidator (Decimal ('0.0' ))]
187+ )
188+ points_possible = models .DecimalField (
189+ decimal_places = 2 ,
190+ default = Decimal ('0.0' ),
191+ max_digits = 6 ,
192+ validators = [MinValueValidator (Decimal ('0.0' ))]
193+ )
182194 created_at = models .DateTimeField (editable = False , default = now , db_index = True )
183195
184196 # Flag to indicate that this score should reset the current "highest" score
@@ -214,9 +226,9 @@ def to_float(self):
214226 float or None
215227
216228 """
217- if self .points_possible == 0 :
229+ if self .points_possible == Decimal ( '0.0' ) :
218230 return None
219- return float (self .points_earned ) / self .points_possible
231+ return float (self .points_earned / self .points_possible )
220232
221233 def __repr__ (self ):
222234 return repr (dict (
@@ -236,7 +248,7 @@ def is_hidden(self):
236248 bool: Whether the score should be hidden.
237249
238250 """
239- return self .points_possible == 0
251+ return self .points_possible == Decimal ( '0.0' )
240252
241253 @classmethod
242254 def create_reset_score (cls , student_item ):
@@ -264,7 +276,7 @@ def create_reset_score(cls, student_item):
264276 student_item = student_item ,
265277 submission = None ,
266278 points_earned = 0 ,
267- points_possible = 0 ,
279+ points_possible = Decimal ( '0.0' ) ,
268280 reset = True ,
269281 )
270282
0 commit comments