2๐
โ
I took a look at TimeStampedModel
and it set a default ordering
in the class meta
:
class TimeStampedModel(models.Model):
""" TimeStampedModel
An abstract base class model that provides self-managed "created" and
"modified" fields.
"""
created = CreationDateTimeField(_('created'))
modified = ModificationDateTimeField(_('modified'))
class Meta:
get_latest_by = 'modified'
ordering = ('-modified', '-created',)
# ^^^^^^^^^^^^^^^^^^^^^^^^^^
abstract = True
You could overwrite that providing another filter to order by (like tipo__nombre
or monto
), ex:
Pago.objects.filter(
created__range=(self.inicio, self.fin)
).values(
'tipo__nombre'
).annotate(
monto=Sum('monto')
).order_by(
'tipo__nombre'
)
๐คRenan Ivo
Source:stackexchange.com