Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions ami/main/migrations/0037_alter_detection_path_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Generated by Django 4.2.10 on 2024-09-04 23:22

from django.db import migrations, models
import django.db.models.deletion


# Method to convert blank path to null in bulk
def convert_blank_path_to_null(apps, schema_editor):
Detection = apps.get_model("main", "Detection")
Detection.objects.filter(path="").update(path=None)


class Migration(migrations.Migration):
dependencies = [
("main", "0036_event_calculated_fields_updated_at_and_more"),
]

operations = [
migrations.AlterField(
model_name="detection",
name="path",
field=models.CharField(blank=True, max_length=255, null=True),
),
migrations.RunPython(convert_blank_path_to_null, reverse_code=migrations.RunPython.noop),
]
4 changes: 2 additions & 2 deletions ami/main/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1695,7 +1695,7 @@ class Detection(BaseModel):
# upload_to="detections",
# ),
# )
path = models.CharField(max_length=255, blank=True)
path = models.CharField(max_length=255, blank=True, null=True)

occurrence = models.ForeignKey(
"Occurrence",
Expand Down Expand Up @@ -1912,7 +1912,7 @@ def duration_label(self) -> str | None:
return ami.utils.dates.format_timedelta(duration)

def detection_images(self, limit=None):
for url in Detection.objects.filter(occurrence=self).values_list("path", flat=True)[:limit]:
for url in Detection.objects.filter(occurrence=self).exclude(path=None).values_list("path", flat=True)[:limit]:
yield urllib.parse.urljoin(_CROPS_URL_BASE, url)

@functools.cached_property
Expand Down
2 changes: 1 addition & 1 deletion ami/ml/models/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ def save_results(results: PipelineResponse, job_id: int | None = None) -> list[m
).first()
if existing_detection:
if not existing_detection.path:
existing_detection.path = detection_resp.crop_image_url or ""
existing_detection.path = detection_resp.crop_image_url or None
existing_detection.save()
print("Updated existing detection", existing_detection)
detection = existing_detection
Expand Down