开发者

Make Django Admin remember my parameters after posting

I have a problems thats been bugging me for a while. I want to use dates in django admin to view entries between certain dates. To do this I have customized my changelist.html for this model and put a form in there. When posted I override the queryset method like this

def queryset(self, request):
    qs = super(ModelAdmin, self).queryset(request)

    if request.POST.has_key('date1'):
        return qs.filter(startdate__gte=request.POST['date1']).filter(startdate__lte=request.POST['date2'])               
    return qs

This works great but its only one little problem. The parameters are forgotten if I for example choose to sort the result i开发者_如何学运维n any way.

If I instead of this type in the url straight into the browser so it looks like this

http//localhost/admin/some/model/?startdate__gte=2010-01-01&startdate__lte=2010-12-30

I can sort however I want to afterwards because they´ll stick just like this http//localhost/admin/some/model/?o=5&ot=asc&startdate__lte=2010-12-30&startdate__gte=2010-01-01

Do I need to use a filterspec to solve this?

Thanks heaps!


There is a change request over at the Django project asking for this functionality.

It's waiting for someone to write tests for the proposed patch before it's committed, so you could either do that or you could download the proposed patch (near the bottom of the page) and use it.

https://code.djangoproject.com/ticket/6903

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜