【发布时间】:2012-10-25 09:19:17
【问题描述】:
在我的模板中,我显示了一个用户关注的用户列表。我希望用户能够通过一个按钮删除他关注的用户之一。 我有一个删除关系的函数 remove_relationship。
这是我的models.py中的函数:
class UserProfile(models.Model):
(...)
def remove_relationship(self, person):
Relationship.objects.filter(
from_person=self,
to_person=person).delete()
return
我想将此函数传递到我的模板中:
{% for user in following % }
<form method="post">
{% csrf_token %}
<input type="submit" value="delete" onclick="remove_relationship"/>
</form>
{%endfor%}
问题是我无法在模板中传递参数。那么如何才能让每个按钮都删除与正确用户的关系呢?
我看到了关于这个主题的另一个问题,但它似乎不能解决我的问题(http://stackoverflow.com/questions/1333189/django-template-system-calling-a-function-inside-模型)
感谢您的帮助。
【问题讨论】:
标签: django