From 6cefd65abb101408fed68f69033c490da548569f Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 5 Jan 2016 10:49:38 -0200 Subject: [PATCH] =?UTF-8?q?Replace=20ChoiceField=20by=20ModelChoiceField?= =?UTF-8?q?=20in=20comiss=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- comissoes/views.py | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/comissoes/views.py b/comissoes/views.py index 3ada3029b..d96dab33c 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -118,14 +118,6 @@ class MateriasView(comissao_crud.CrudDetailView): class ReunioesView(comissao_crud.CrudDetailView): template_name = 'comissoes/reunioes.html' -PARLAMENTARES_CHOICES = [('', '---------')] + [ - (p.parlamentar.id, - p.parlamentar.nome_parlamentar + ' / ' + p.partido.sigla) - for p in Filiacao.objects.filter( - data_desfiliacao__isnull=True, parlamentar__ativo=True).order_by( - 'parlamentar__nome_parlamentar')] - - class ParticipacaoCadastroForm(ModelForm): YES_OR_NO = ( @@ -133,11 +125,14 @@ class ParticipacaoCadastroForm(ModelForm): (False, 'Não') ) - parlamentar_id = forms.ChoiceField(required=True, - label='Parlamentar', - choices=PARLAMENTARES_CHOICES, - widget=forms.Select( - attrs={'class': 'selector'})) + parlamentar_id = forms.ModelChoiceField( + label='Parlamentar', + required=True, + queryset=Filiacao.objects.filter( + data_desfiliacao__isnull=True, parlamentar__ativo=True).order_by( + 'parlamentar__nome_parlamentar'), + empty_label='Selecione', + ) titular = forms.BooleanField( widget=forms.RadioSelect(choices=YES_OR_NO), required=True)