Skip to content

Instantly share code, notes, and snippets.

@eka
Created March 24, 2014 16:44
Show Gist options
  • Save eka/9744127 to your computer and use it in GitHub Desktop.
Save eka/9744127 to your computer and use it in GitHub Desktop.
class ComercioParticipanteFilter(SimpleListFilter):
title = 'Comercio Participante'
parameter_name = 'com_participante'
def lookups(self, request, model_admin):
if request.user.is_superuser:
return (('Todos/as',''),)
# Esto lo vamos a usar en el futuro, para darle un <select> al admin.
# return [(x['num_com'], x['num_com']) for x in model_admin.model.objects.values("num_com").annotate(count=Count('num_com'))]
else:
return [(x.numero, x.nombre) for x in request.user.empresa.compart_set.all()]
def queryset(self, request, query_set):
value = self.value()
usuario = request.user
if not usuario.is_superuser and usuario.empresa.compart_set.filter(numero=value):
return query_set.filter(comercio_participante=value)
else:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment