diff --git a/sapl/materia/migrations/0030_tramitacao_timestamp.py b/sapl/materia/migrations/0030_tramitacao_timestamp.py new file mode 100644 index 000000000..338f991ad --- /dev/null +++ b/sapl/materia/migrations/0030_tramitacao_timestamp.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-09-18 12:13 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0029_auto_20180901_1628'), + ] + + operations = [ + migrations.AddField( + model_name='tramitacao', + name='timestamp', + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index a43a798b0..6bcb6f8c0 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -908,6 +908,9 @@ class Tramitacao(models.Model): null=True, verbose_name=_('Status')) materia = models.ForeignKey(MateriaLegislativa, on_delete=models.CASCADE) + # TODO: Remover os campos de data + # TODO: pois timestamp supre a necessidade + timestamp = models.DateTimeField(default=timezone.now) data_tramitacao = models.DateField(verbose_name=_('Data Tramitação')) unidade_tramitacao_local = models.ForeignKey( UnidadeTramitacao, diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 050be7ba6..9e738dbe9 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1080,6 +1080,7 @@ class TramitacaoCrud(MasterDetailCrud): ultima_tramitacao = Tramitacao.objects.filter( materia_id=self.kwargs['pk']).order_by( '-data_tramitacao', + '-timestamp', '-id').first() if ultima_tramitacao: @@ -1150,6 +1151,7 @@ class TramitacaoCrud(MasterDetailCrud): qs = super(MasterDetailCrud.ListView, self).get_queryset() kwargs = {self.crud.parent_field: self.kwargs['pk']} return qs.filter(**kwargs).order_by('-data_tramitacao', + '-timestamp', '-id') class DeleteView(MasterDetailCrud.DeleteView): @@ -1162,6 +1164,7 @@ class TramitacaoCrud(MasterDetailCrud): ultima_tramitacao = materia.tramitacao_set.order_by( '-data_tramitacao', + '-timestamp', '-id').first() if tramitacao.pk != ultima_tramitacao.pk: