Created
March 24, 2014 13:50
-
-
Save gtsalles/9740442 to your computer and use it in GitHub Desktop.
Busca Avançada no Admin
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
def get_changelist(self, request, **kwargs): | |
cl = super(CurriculoAdmin, self).get_changelist(request, **kwargs) | |
class CustomCL(cl): | |
def get_queryset(self, *args, **kwargs): | |
qs = super(CustomCL, self).get_queryset(*args, **kwargs) | |
# deveria montar a query baseadas nos parametros get que passei e | |
# retornar o novo queryset mas não consigo pegar os parâmetros do get | |
return qs.filter(query) | |
return CustomCL |
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
def get_urls(self): | |
urls = super(CurriculoAdmin, self).get_urls() | |
u = patterns('', url(r'^filtro/$', self.filtro, name='filtro')) | |
return u + urls | |
# Assim vai "sem queryset" | |
def filtro(self, request): | |
cl = self.get_changelist(request) | |
context = {'cl': cl} | |
return render(request, 'admin/change_list.html', context) | |
# tentei sobrescrever o get_queryset mas também não vai | |
def filtro(self, request): | |
cl = self.get_changelist(request) | |
class CustomCL(cl): | |
def get_queryset(self, request): | |
# Não chega nem a entrar nesse método, tentei inclusive retornar um | |
# MyModel.objects.all() e continua sem exibir nada | |
qs = super(CustomCL, self).get_queryset(*args, **kwargs) | |
return qs | |
context = {'cl': CustomCL} | |
return render(request, 'admin/change_list.html', context) |
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
def lookup_allowed(self, lookup, value): | |
fields = (...) | |
if lookup in fields: | |
return True | |
return super(MyModelAdmin, self).lookup_allowed(lookup, value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment