Created
March 24, 2014 16:44
-
-
Save eka/9744127 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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