django pagination: How to get number of page by id of element in the list
I use django-paginaton app and I'm very glad to use it. Now I need feature, that I don't know how to implement. I have list of elements, that paginated by django's paginator. I have one element with specified id, that I should show, but I don't know what page contains it. I need mechanism jump to the pa开发者_高级运维ge, that contains my element.
I think it's a good idea if django-pagination will support this transparently and automatically. For example, I set special context variable page_by_id
to X and if page
is None, it will be defined to the value, that contains my X element.
What do you think about this mechanism? May be there is another clean way to do this?
This is for continue of this questions:
- Django pagination and "current page"
- Django Pagination - Redirecting to the page an object is on
At least, I wrote patch for django-pagination that provide 2 features:
- Get number of page by id of element inside paginated list;
- Possibility to rename default parameter 'page' to another value for using it inside template;
This works transparently by adding 2 optional parameters in autopaginate templatetag:
{% autopaginate object_list paginated_by orphans page_by_id parameter_name %}
精彩评论