私のテンプレートでは、ユーザーがフォローしているユーザーのリストを表示します。ボタンのおかげで、ユーザーがフォローしているユーザーの1人を削除できるようにしたいと思います。リレーションシップを削除する関数 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-a-model )
ご協力ありがとうございました。