|
@ -45,7 +45,7 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec): |
|
|
|
|
|
|
|
|
my_municipio_field.uf_filter = True |
|
|
my_municipio_field.uf_filter = True |
|
|
|
|
|
|
|
|
On Django 1.2 you will can specify a lookup on admin filters. Example: |
|
|
On Django 1.3 you will can specify a lookup on admin filters. Example: |
|
|
|
|
|
|
|
|
list_filter = ('municipio__uf',) |
|
|
list_filter = ('municipio__uf',) |
|
|
|
|
|
|
|
@ -74,6 +74,42 @@ class MunicipioUFFilterSpec(ChoicesFilterSpec): |
|
|
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), |
|
|
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), |
|
|
MunicipioUFFilterSpec)) |
|
|
MunicipioUFFilterSpec)) |
|
|
|
|
|
|
|
|
|
|
|
class ConvenioUFFilterSpec(ChoicesFilterSpec): |
|
|
|
|
|
""" |
|
|
|
|
|
Usage: |
|
|
|
|
|
|
|
|
|
|
|
municipio.uf_filter = True |
|
|
|
|
|
|
|
|
|
|
|
On Django 1.3 you will can specify a lookup on admin filters. Example: |
|
|
|
|
|
|
|
|
|
|
|
list_filter = ('municipio__uf',) |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
|
|
|
|
def __init__(self, f, request, params, model, model_admin): |
|
|
|
|
|
super(ConvenioUFFilterSpec, self).__init__(f, request, params, model, |
|
|
|
|
|
model_admin) |
|
|
|
|
|
self.lookup_kwarg = '%s__municipio__uf__codigo_ibge__exact' % f.name |
|
|
|
|
|
self.lookup_val = request.GET.get(self.lookup_kwarg, None) |
|
|
|
|
|
self.lookup_choices = UnidadeFederativa.objects.all().order_by('nome') |
|
|
|
|
|
|
|
|
|
|
|
def choices(self, cl): |
|
|
|
|
|
yield {'selected': self.lookup_val is None, |
|
|
|
|
|
'query_string': cl.get_query_string({}, [self.lookup_kwarg]), |
|
|
|
|
|
'display': _('All')} |
|
|
|
|
|
for val in self.lookup_choices: |
|
|
|
|
|
yield {'selected': smart_unicode(val.codigo_ibge) == self.lookup_val, |
|
|
|
|
|
'query_string': cl.get_query_string({self.lookup_kwarg: val.codigo_ibge}), |
|
|
|
|
|
'display': val.nome} |
|
|
|
|
|
def title(self): |
|
|
|
|
|
return _('UF') % \ |
|
|
|
|
|
{'field_name': self.field.verbose_name} |
|
|
|
|
|
|
|
|
|
|
|
# registering the filter |
|
|
|
|
|
FilterSpec.filter_specs.insert(0, (lambda f: getattr(f, 'uf_filter', False), |
|
|
|
|
|
ConvenioUFFilterSpec)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class RangeValuesFilterSpec(FilterSpec): |
|
|
class RangeValuesFilterSpec(FilterSpec): |
|
|
""" |
|
|
""" |
|
|
Author: Willie Gollino (wgollino@yahoo.com) |
|
|
Author: Willie Gollino (wgollino@yahoo.com) |
|
|