@@ -1821,6 +1821,9 @@ def get_score_fieldnames(cls) -> List[str]:
18211821 y_tl = models .PositiveIntegerField (help_text = "photo bounding box coordinates top left y" )
18221822 y_br = models .PositiveIntegerField (help_text = "photo bounding box coordinates bottom right y" )
18231823
1824+ height = models .PositiveIntegerField (null = True )
1825+ width = models .PositiveIntegerField (null = True )
1826+
18241827 created_at = models .DateTimeField (auto_now_add = True , editable = False )
18251828 updated_at = models .DateTimeField (auto_now = True , editable = False )
18261829
@@ -1839,18 +1842,12 @@ def uncertainty(self) -> float:
18391842 ])
18401843
18411844 def clean (self ):
1842- # Get the linked photo dimensions
1843- try :
1844- width , height = self .photo .photo .width , self .photo .photo .height
1845- except FileNotFoundError :
1846- width = height = None
1847-
18481845 # Check if x_br is greater than the photo width
1849- if width is not None and self .x_br > width :
1846+ if self . width is not None and self .x_br > self . width :
18501847 raise ValidationError ("Bottom right x-coordinate (x_br) cannot exceed the width of the photo." )
18511848
18521849 # Check if y_br is greater than the photo height
1853- if height is not None and self .y_br > height :
1850+ if self . height is not None and self .y_br > self . height :
18541851 raise ValidationError ("Bottom right y-coordinate (y_br) cannot exceed the height of the photo." )
18551852
18561853 if self .is_decisive :
@@ -1867,6 +1864,11 @@ def clean(self):
18671864 def save (self , * args , ** kwargs ):
18681865 self .taxon = Taxon .objects .filter (pk = self .PREDICTED_CLASS_TO_TAXON [self .predicted_class ]).first ()
18691866
1867+ try :
1868+ self .width , self .height = self .photo .photo .width , self .photo .photo .height
1869+ except FileNotFoundError :
1870+ self .width = self .height = None
1871+
18701872 self .clean ()
18711873
18721874 if self .is_decisive :
0 commit comments