Developer 2024 🎇限时优惠进行中,现在购买立即享受

现在购买

admin中的layer弹出层问题

avatar34B4A3F6
6月22日289次阅读

我写了一个通用的批量修改模型的方法,想把这个方法从单个模型抽离到通用的公共组件中,但是在公共组件中,layer无法正常获取。

    def querysets_update_config(self, request, queryset):
        return {
            'title': '测试批量修改',
            'params': [{
                'type': 'radio',
                'key': 'type',
                'label': '修改类型',
                'require': True,
                'value': 1,
                'options': [{
                    'key': 1,
                    'label': '更新'
                }, {
                    'key': 0,
                    'label': '新增'
                }]
            }, {
                'type': 'checkbox',
                'key': 'ck',
                'label': 'Checkbox',
                'require': True,
                'value': [1],
                'options': [{
                    'key': 1,
                    'label': '更新'
                }, {
                    'key': 0,
                    'label': '新增'
                }]
            }]
        }

    @layer(querysets_update_config)
    def querysets_update(self, request, queryset):
        # 这里的queryset 会有数据过滤,只包含选中的数据
        post = request.POST
        field_name = post.get('field_name')
        # print(field_name)
        old_value = post.get('old_value')
        new_value = post.get('new_value')
        # post中 _selected 是选中的数据,逗号分割
        if not post.get('_selected') and post.get('select_across') == '0':
            return JsonResponse(data={
                'status': 'error',
                'msg': '请先选中数据!'
            })
        else:
            kwargs = {f'{field_name}__icontains': old_value}
            queryset = queryset.filter(**kwargs)

            return JsonResponse(data={'status': 'success','msg': '处理成功!'})

查看后台报错如下

ERROR 2024-06-22 18:02:04,844 log 3952 5564 Internal Server Error: /admin/apps_xxxx/modelname/layer
Traceback (most recent call last):
  File "\Lib\site-packages\asgiref\sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "\Lib\site-packages\django\core\handlers\exception.py", line 42, in inner
    response = await get_response(request)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\Lib\site-packages\asgiref\sync.py", line 518, in thread_handler
    raise exc_info[1]
  File "\Lib\site-packages\django\core\handlers\base.py", line 253, in _get_response_async
    response = await wrapped_callback(
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "\Lib\site-packages\asgiref\sync.py", line 468, in __call__
    ret = await asyncio.shield(exec_coro)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\Lib\site-packages\asgiref\current_thread_executor.py", line 40, in run
    result = self.fn(*self.args, **self.kwargs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "\Lib\site-packages\asgiref\sync.py", line 522, in thread_handler
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "\Lib\site-packages\simpleui\admin.py", line 158, in get_layer
    arg_count = func.layer.__code__.co_argcount
                ^^^^^^^^^^^^^^^^^^^
AttributeError: 'dict' object has no attribute '__code__'. Did you mean: '__doc__'?
发布评论
登录后发表内容
3个评论