Thursday, November 22, 2012

SimpleListFilter is giving "NotImplementedError"

Hola,

After successfully implementing two range based filters using the admin's list_filter docs: PATH/ref/contrib/admin/index.html#django.contrib.admin.ModelAdmin.list_filter

I've added one more filter, but now I'm getting a NotImplementedError and I can't see what I've done wrong. The model has a field called "island" and I would like to distinguish between the main island and the "outer islands" (all the rest). Note the commented out returns - me trying to find any subtle changes to fix this:

class IslandFilter(admin.SimpleListFilter):
    title = 'islands'
    parameter_name = 'island'
    
    def lookup(self, request, model_admin):
        return (
            ('tarawa', 'Tarawa'),
            ('outer-islands', 'Outer Islands'),
        )   

    def queryset(self, request, queryset):
        if self.value == 'tarawa':
            return queryset.filter(island=='Tarawa')
            #return queryset.filter(island__exact='Tarawa')
        else:
            return queryset.exclude(island=='Tarawa')
            #return queryset.exclude(island__exact='Tarawa')


class ApplicantAdmin(admin.ModelAdmin):
     list_filter = ('gender', 'disability', MathTestFilter, EnglishTestFilter, IslandFilter,'successful', 'applied_for', 'eligibility')

Can anyone see what I've done wrong please?


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 django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate