[ERROR][2023-06-08 13:17:01,837][log.py:230]Internal Server Error: /admin/material_scrap/materialscraphead/69/change/ Traceback (most recent call last): File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\core\handlers\exception.py", line 47, in inner response = get_response(request) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\core\handlers\base.py", line 181, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\contrib\admin\options.py", line 616, in wrapper return self.admin_site.admin_view(view)(*args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\views\decorators\cache.py", line 44, in _wrapped_view_func response = view_func(request, *args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\contrib\admin\sites.py", line 232, in inner return view(request, *args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\contrib\admin\options.py", line 1660, in change_view return self.changeform_view(request, object_id, form_url, extra_context) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\utils\decorators.py", line 43, in _wrapper return bound_method(*args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\utils\decorators.py", line 130, in _wrapped_view response = view_func(request, *args, **kwargs) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\contrib\admin\options.py", line 1540, in changeform_view return self._changeform_view(request, object_id, form_url, extra_context) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\contrib\admin\options.py", line 1586, in _changeform_view self.save_model(request, new_object, form, not add) File "C:\work\django_app\dj_erp\apps\material_scrap\admin.py", line 138, in save_model reason = request.POST['materialscrapdetail_set-0-reason'] File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\db\models\base.py", line 485, in __init__ _setattr(self, field.name, rel_obj) File "C:\Users\suzisxue\Anaconda3\envs\django_dev\lib\site-packages\django\db\models\fields\related_descriptors.py", line 220, in __set__ self.field.remote_field.model._meta.object_name, ValueError: Cannot assign "<class 'material_scrap.models.MaterialScrapHead'>": "MaterialScrapDetail.serialNum" must be a "MaterialScrapHead" instance.
时间: 2023-07-17 19:54:30 浏览: 144
这个错误提示是在 Django 管理界面(admin)操作 `material_scrap.models.MaterialScrapHead` 这个模型时出现的,具体是在 `save_model` 方法中,尝试获取 `request.POST['materialscrapdetail_set-0-reason']` 时出现了问题。
根据错误提示,可以看到是 `MaterialScrapDetail.serialNum` 属性应该是 `MaterialScrapHead` 类型的实例,但是却传入了 `class 'material_scrap.models.MaterialScrapHead'` 这个类对象,所以出现了错误。
需要检查你的代码,确认 `MaterialScrapDetail.serialNum` 属性是否正确设置,并且在获取 `request.POST` 参数时是否正确,建议先在代码中加入一些调试信息,逐步排查问题。
阅读全文