Skip to content

Instantly share code, notes, and snippets.

@zodman
Created December 7, 2010 18:11
Show Gist options
  • Save zodman/732164 to your computer and use it in GitHub Desktop.
Save zodman/732164 to your computer and use it in GitHub Desktop.
un filter fuera de lo comun
# coding: utf-8
from django.template import Library
from django.db import models
from django.utils.translation import ugettext as _
register = Library()
def estado_filter(cl):
if not getattr(cl.model_admin, 'estado_filter', False):
return
field_name = cl.model_admin.estado_filter
alpha_field = '%s__exact' % field_name
alpha_lookup = cl.params.get(alpha_field, '')
link = lambda d: cl.get_query_string(d)
all_letters = {'4':'En revisión','1':'Autorizado','3':'Rechazado','2':'Facturación',}
lista = ['4','1','3','2']
choices = [{
'link': link({alpha_field: letter}),
'title': all_letters[letter],
'active': letter == alpha_lookup,
'has_entries': True,} for letter in lista]
all_letters = [{
'link': cl.get_query_string(None,alpha_field),
'title': _('All'),
'active': '' == alpha_lookup,
'has_entries': True
},]
return {'choices': all_letters + choices}
estado_filter = register.inclusion_tag('admin/estado_filter.html')(estado_filter)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment