私にはこの問題を解決する手がかりがありません。
オブジェクトを受け取るテンプレートタグがあります:
{% score_for_object OBJECT_HERE as score2 %}
問題は、生の選択から取得したコンテキストをテンプレートに渡すことです。
cursor = connection.cursor()
cursor.execute("select ...")
comments = utils.dictfetchall(cursor)
Djangoオブジェクトを受け入れるテンプレートタグの問題を解決するために、テンプレートタグを作成しました。
'''
This template tag is used to transform a comment_id in an object to use in the django-voting app
'''
def retrive_comment_object(comment_id):
from myapp.apps.comments.models import MPTTComment
return MPTTComment.objects.get(id=comment_id)
このテンプレートタグを使用すると、これが機能することを期待していました。
{% for item in comments %}
{% score_for_object item.comment_id|retrieve_comment_object as score2 %}
{{ score2.score }} {# expected to work, but not working #}
{% endfor %}
私の質問。テンプレートタグからオブジェクトを取得することは可能ですか?
よろしくお願いします、