Hello there,

I've just posted a patch with a suggested implementation of custom
admin filters: 
http://code.djangoproject.com/attachment/ticket/5833/5833.custom-filterspecs.3.diff

I've written some pretty comprehensive tests and have also had a stab
at writing some documentation. You should find all the details there
but I thought I'd give a little teaser here first. Here's an example
of what you could do with it:

The model:

    class Book(Model):
        title = models.CharField()
        pages = models.PositiveIntegerField()

The admin:

    from django.contrib import admin

    class BookSizeFilter(admin.SimpleListFilter):

        def get_title(self):
            return u'size'

        def get_choices(self, request):
            return (
                (u'small', u'Small'),
                (u'medium', u'Medium'),
                (u'large', u'Large'),
            )

        def get_query_set(self, changelist, queryset):
            size = self.get_value()
            if size == u'small':
                return queryset.filter(pages__gte=1, pages__lte=100)
            if size == u'medium':
                return queryset.filter(pages__gte=101, pages__lte=200)
            if size == u'large':
                return queryset.filter(pages__gte=201)
            return queryset

    class BookAdmin(admin.ModelAdmin):
        list_filter = [BookSizeFilter,]

Custom filters is a feature that has been requested by many people and
for a long time. If you're one of those eager people, it would be
awesome if you could take a look at the patch and, if you like the
proposed API, try it in your own real projects to see if all the edge
cases are covered.

I'm also really keen to hear your thoughts on the various sub-features
that ship with that patch, on the suggested API, and on the various
implementation details.

The patch is pretty hefty so I'd really like to take this to a close
ASAP before it grows stale and becomes harder to maintain.

Many thanks!

Julien :-)

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers" group.
To post to this group, send email to django-developers@googlegroups.com.
To unsubscribe from this group, send email to 
django-developers+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-developers?hl=en.

Reply via email to