I have a user model, an item model, and a possession model to store data about a user possessing an item. When a user is logged in and viewing an item, I want to display an 'add to my items' button, unless the user already has the item.
I was trying this code in the template:
{% if not user.possession_set.filter(item=item.id) %}
<input type='submit' value='add to my items' />
{% endif %}
where item is the foreign key name for the item object in my possession model and item.id is the primary key for the item being displayed to the user
but I get this error:
Could not parse the remainder: '(item=item.id)'
I'm thinking I can't use the .filter() function since that is for querying the database? I found django's template filters, like this one: http://docs.djangoproject.com/en/1.1/ref/templates/builtins/#get-digit but there aren't any that can be combined to filter for a certain value of item. It seems I would have all the information in the template to do this, since I'm getting the user and it's possession_set, which should have the item field for each possession, so I'm thinking it's just a syntax thing?
Thanks for the help!