3

I'm trying to get 5 foo objects whose children (bar) have the longest combined duration:

    foo = Foo.objects.annotate( sum_of_bar_duration=Sum("bar__duration") )\
        .order_by('-sum_of_bar_duration')[:5]

My Models:

class Foo(models.Model):

      name = models.CharField(max_length=30, unique=True)

class Bar(models.Model):

      foo = models.ForeignKey(Foo, on_delete=models.CASCADE)
      
      duration = models.DurationField()

But I ended up getting this error:
django.core.exceptions.FieldError: Unsupported lookup 'duration' for BigAutoField or join on the field not permitted.
Does anyone know why? How can I fix this?

newbCoder
  • 31
  • 2

0 Answers0