I can't figure out how to use mezzanine pagination for my custom models.
The docs say:
mezzanine.core.templatetags.mezzanine_tags.pagination_for(parser, token) Include the pagination template and data for persisting querystring in pagination links. Can also contain a comma separated string of var names in the current querystring to exclude from the pagination links, via the exclude_vars arg.
As far as I understand in my template file I have to include mezzanine_tags
and call {% pagination_for parser token %}
.
I don't really understand what are parser and token. I looked at the source code of that template tag and it it as follows:
@register.inclusion_tag("includes/pagination.html", takes_context=True)
def pagination_for(context, current_page, page_var="page", exclude_vars=""):
"""
Include the pagination template and data for persisting querystring
in pagination links. Can also contain a comma separated string of
var names in the current querystring to exclude from the pagination
links, via the ``exclude_vars`` arg.
"""
querystring = context["request"].GET.copy()
exclude_vars = [v for v in exclude_vars.split(",") if v] + [page_var]
for exclude_var in exclude_vars:
if exclude_var in querystring:
del querystring[exclude_var]
querystring = querystring.urlencode()
return {
"current_page": current_page,
"querystring": querystring,
"page_var": page_var,
}
Buy looking at usage I think that token is just number denoting current page. But how do I get context
in the template?