Created
September 26, 2016 00:38
-
-
Save ramiroluz/09866153e01a8ea0e1cf37bd4c7a94d1 to your computer and use it in GitHub Desktop.
Trecho do forms.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ContatoAgrupadoPorGrupoFilterSet(FilterSet): | |
search = MethodFilter() | |
municipio = MethodModelChoiceFilter( | |
required=False, | |
queryset=Municipio.objects.all()) | |
grupo = MethodModelChoiceFilter( | |
required=False, | |
queryset=GrupoDeContatos.objects.all()) | |
def filter_municipio(self, queryset, value): | |
import pdb; pdb.set_trace() | |
queryset = queryset.filter(nome=value) | |
return queryset | |
def filter_grupo(self, queryset, value): | |
queryset = queryset.filter(nome=value) | |
return queryset | |
class Meta: | |
model = Contato | |
fields = ['municipio', ] | |
def __init__(self, data=None, | |
queryset=None, prefix=None, strict=None, **kwargs): | |
workspace = kwargs.pop('workspace') | |
super(ContatoAgrupadoPorGrupoFilterSet, self).__init__( | |
data=data, | |
queryset=queryset, prefix=prefix, strict=strict, **kwargs) | |
c1_row1 = to_row([ | |
('municipio', 7), | |
('grupo', 7), | |
]) | |
col1 = Fieldset( | |
_('Informações para Seleção de Contados'), | |
c1_row1, | |
to_row([ | |
(SubmitFilterPrint( | |
'filter', | |
value=_('Filtrar'), | |
css_class='btn-default pull-right', | |
type='submit'), 12) | |
])) | |
col2 = Fieldset( | |
_('Inf p/ Impressão'), | |
SubmitFilterPrint( | |
'print', | |
value=_('Imprimir'), | |
css_class='btn-primary pull-right', | |
type='submit') | |
) | |
rows = to_row([ | |
(col1, 9), | |
(col2, 3), | |
]) | |
self.form.helper = FormHelper() | |
self.form.helper.form_method = 'GET' | |
self.form.helper.layout = Layout( | |
rows, | |
) | |
self.form.fields['grupo'].queryset = GrupoDeContatos.objects.filter( | |
workspace=workspace) | |
self.form.fields['municipio'].queryset = Municipio.objects.all() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment