class TestModel(models.Model):
name = models.IntegerField()
created = models.DateTimeField()
dt = timezone.now()
for i in range(5):
TestModel(
name=str(i),
created=dt
).save()
obj = TestModel.objects.all().order_by('created')
print(obj.first().name)
print(obj.last().name)
}}}
Both print statements above will print 0
--
Ticket URL: <https://code.djangoproject.com/ticket/30901>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* cc: Tadas (added)
* type: Uncategorized => Bug
--
Ticket URL: <https://code.djangoproject.com/ticket/30901#comment:1>
* status: new => closed
* resolution: => invalid
Comment:
Ordering on a non-unique field is undefined.
Since all your `TestModel` share the same `created` both `ORDER BY
created_at LIMIT 1` and `ORDER BY created_at DESC LIMIT 1` can return the
same value. This is just how your database backend decides to return it.
--
Ticket URL: <https://code.djangoproject.com/ticket/30901#comment:2>