Skip to content

Commit 783383c

Browse files
committed
Save width/height in PhotoPrediction
1 parent a0e0cdc commit 783383c

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Generated by Django 3.2.25 on 2025-06-16 14:27
2+
3+
from django.db import migrations, models
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('tigacrafting', '0033_add_photoprediction'),
10+
]
11+
12+
operations = [
13+
migrations.AddField(
14+
model_name='photoprediction',
15+
name='height',
16+
field=models.PositiveIntegerField(null=True),
17+
),
18+
migrations.AddField(
19+
model_name='photoprediction',
20+
name='width',
21+
field=models.PositiveIntegerField(null=True),
22+
),
23+
]

tigacrafting/models.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)