我在我的项目中使用django-reversion app。
我有 ManyToMany字段“评论”的模态“任务”。在我的项目中,我有一个带有revertions列表的页面。它在评论的注释字段ID中显示了我。 例如:comments(field_name):[66,67,68](field_value)。
获取该id-s并显示评论信息(作者,文本,创建)的最佳方式不仅仅是id。可能吗?我有点沮丧。
models.py:
@reversion.register()
class Task(models.Model):
comments = models.ManyToManyField("Comment")
class Comment(models.Model):
author = models.ForeignKey(User, on_delete=models.CASCADE)
text = models.TextField()
created = models.DateTimeField(auto_now_add=True)
views.py:
def task_reversions(request, project_code, task_code):
project = get_object_or_404(Project, pk=project_code, status='open')
task = get_object_or_404(GroupTask, pk=group_task_code)
versions = Version.objects.get_for_object(ask)
context = {
'project': project,
'task': task,
'versions': versions,
}
return render(request, 'project/task_reversions.html', context)
task_reversions.html:
{% for field_name, field_value in version.field_dict.items %}
{{ field_name }}
{{ field_value }}
{% endfor %}