Why does my Django models.Manager return all objects on a relationship?
I don't particularly understand what's going on here, but it seems that super().get_queryset()
doesn't do what I think it does?
I have 1:N relationship, and the default FK reverse lookup works:
>>> for thing in this.thing_set.all():
... print(thing.this)
Each one of these is This
.
However, with my customized:
>>> for thing in this.thing_set.by_date():
... print(thing.this)
Will produced This
and `That*
class ThingByDateManager(models.Manager):
def by_date(self):
return super().get_queryset().order_by("start_time")
That's all there is.
class This(models.Model):
name = models.CharField(max_length=255, primary_key=True)
class Thing(models.Model):
start_time = models.DateTimeFiled()
name = models.CharField(max_length=255)
this = models.ForeignKey(This, on_delete=models.CASCADE)
objects = ThingByDateManager()
(might not have those models perfectly written, but I'm hoping it's just something silly with the queryset or something)
Why doesn't this correctly filter my objects by this
, instead returning all of the Thing
s?
I don't know if this is the correct way to do it, but:
return super().all().order_by("start_time")
Seems to work, but I'm not sure why that's different