diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index a31015a8f..4f843ed03 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -6,7 +6,7 @@ from django.contrib.auth.decorators import permission_required from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.urlresolvers import reverse -from django.db.models import Q +from django.db.models import Max, Q from django.forms.utils import ErrorList from django.http import JsonResponse from django.http.response import Http404, HttpResponseRedirect @@ -162,6 +162,9 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): def get_initial(self): self.initial['data_ordem'] = SessaoPlenaria.objects.get( pk=self.kwargs['pk']).data_inicio.strftime('%d/%m/%Y') + max_numero_ordem = OrdemDia.objects.filter( + sessao_plenaria=self.kwargs['pk']).aggregate(Max('numero_ordem'))['numero_ordem__max'] + self.initial['numero_ordem'] = (max_numero_ordem if max_numero_ordem else 0) + 1 return self.initial def get_success_url(self):