from django.db import models from django.contrib.auth.models import User class Detection(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE, null=True, blank=True) image = models.ImageField(upload_to='detections/') results = models.JSONField() # Stores the list of detected objects created_at = models.DateTimeField(auto_now_add=True) def __str__(self): count = len(self.results) if self.results else 0 return f"Detection {self.id} ({count} objects) - {self.created_at.strftime('%Y-%m-%d %H:%M')}"