我有 2 个问题导致对django-reversion应用程序有点困惑。我有页面,用户可以在其中查看所有版本的列表。每个版本都有恢复按钮。
1 问题:如何仅显示某些更改字段。现在它向我显示了所有字段。我使用 version.field_dict.items。
2 问题:如何正确恢复到特定版本?
在下面您可以看到代码,但是当我尝试单击以还原链接时,它会在 views.py 中引发错误。我做错了什么?
模板.html
{% for version in versions %}
{% for field_name, field_value in version.field_dict.items %}
{{ field_name }}
{{ field_value }}
{% endfor %}
<a href="{% url 'project:group_task_revert' project_code=project.code group_task_code=group_task.code group_task_reversion_id=version.revision.id%}">REVERT</a>
{% endfor %}
网址.py:
url(r'^(?P<project_code>[0-9a-f-]+)/(?P<group_code>[0-9a-f-]+)/(?P<group_reversion_id>\d+)/$',
group_revert,
name='group_revert'),
视图.py:
def group_revert(request, project_code, group_code, group_reversion_id):
project = get_object_or_404(Project, pk=project_code, status='open')
group = get_object_or_404(Group, pk=group_code)
versions = Version.objects.get_for_object(group)
versions[group_reversion_id].revision.revert()
return redirect('project:project_detail', project_code=project.code)
错误:
Internal Server Error: /ru/account/dashboard/projects/42442299-97dd-4d92-9ef1-880f9cdd1612/4d3d3422-2618-4d66-96f5-8f0a0b5d9bf3/21/
Traceback (most recent call last):
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\exception.py", line 39, in inner
response = get_response(request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\core\handlers\base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\Nurzhan\PycharmProjects\RMS\project\views.py", line 198, in group_revert
versions[group_reversion_id].revision.revert()
File "C:\Users\Nurzhan\AppData\Local\Programs\Python\Python35-32\lib\site-packages\django\db\models\query.py", line 271, in __getitem__
raise TypeError
TypeError