Django - use template tag and 'with'?

Posted by AP257 on Stack Overflow See other posts from Stack Overflow or by AP257
Published on 2010-04-23T10:19:47Z Indexed on 2010/04/23 10:23 UTC
Read the original article Hit count: 231

Filed under:

I have a custom template tag:

def uploads_for_user(user):
    uploads = Uploads.objects.filter(uploaded_by=user, problem_upload=False)
    num_uploads = uploads.count()
    return num_uploads

and I'd like to do something like this, so I can pluralize properly:

{% with uploads_for_user leader as upload_count %}
    {{ upload_count }} upload{{ upload_count|pluralize }}
{% endwith %}

However, uploads_for_user leader doesn't work in this context, because the 'with' tag expects a single value - Django returns:

TemplateSyntaxError at /upload/
u'with' expected format is 'value as name'

Any idea how I can get round this?

© Stack Overflow or respective owner

Related posts about django