Skip to content

Instantly share code, notes, and snippets.

@gtsalles
Created March 24, 2014 13:50
Show Gist options
  • Save gtsalles/9740442 to your computer and use it in GitHub Desktop.
Save gtsalles/9740442 to your computer and use it in GitHub Desktop.
Busca Avançada no Admin
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
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)
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