Hola,
Still with the same code base - now it's rendering, but I'm not getting the
results I expect from the filter.
A model with an 'island' field that's a choice list. I want to distinguish
between one island in particular (Tarawa) and the rest (the Outer Islands).
The results I'm expecting are as per the SimpleListFilter, clicking on
either Tarawa or Outer Islands (as def'd in the lookups) should return the
queryset of Applicants with those attributes. What I'm getting on both is
an unfiltered list (ie, nothing is excluded, both return the same data set
as "All"):
class IslandFilter(admin.SimpleListFilter):
title = 'islands'
parameter_name = 'island'
def lookups(self, request, model_admin):
return (
('tarawa', 'Tarawa'),
('outer-islands', 'Outer Islands'),
)
def queryset(self, request, queryset):
if self.value == 'tarawa':
return queryset.filter(island__iexact='tarawa')
if self.value == 'outer-islands':
return queryset.exclude(island__iexact='tarawa')
When I run the filters in shell, I get the expected response - just not in
the admin interface:
>>> qs = Applicant.objects.filter(island__iexact='tarawa')
>>> for q in qs: print q.island
...
Tarawa
Tarawa
Tarawa
Tarawa
Tarawa
Tarawa
>>> qs = Applicant.objects.exclude(island__iexact='tarawa')
>>> for q in qs: print q.island
...
Marakei
Marakei
Abaiang
Marakei
Butaritari
Kiritimati
>>>
Any ideas on what I'm doing wrong?
Cheers
L.
--
...we look at the present day through a rear-view mirror. This is something
Marshall McLuhan said back in the Sixties, when the world was in the grip
of authentic-seeming future narratives. He said, “We look at the present
through a rear-view mirror. We march backwards into the future.”
http://www.warrenellis.com/?p=14314
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.