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

现在购买

升级7.0和7.1版本后, 双击页面编辑,点保存会报错:Object of type __proxy__ is not JSON serializable

avatarA0E4BFAA
11月2日340次阅读

from django.db import models

Create your models here.

from simplepro.dialog import ModalDialog

class Dialog(models.Model): name = models.CharField(max_length=128, verbose_name='名称', null=True, blank=True) description = models.TextField(verbose_name='描述', null=True, blank=True)

class Meta:
    verbose_name = '对话框'
    verbose_name_plural = verbose_name


def __str__(self):
    return self.name

这个是models的代码,这个代码用的是官方的demo,以下是admin.py的代码 from django.contrib import admin from django.urls import reverse from django.utils.html import format_html

from dialog.models import Dialog from simplepro.dialog import ModalDialog, MultipleCellDialog

@admin.register(Dialog) class DialogAdmin(admin.ModelAdmin): list_editable = ['name', 'description'] list_display = ('id', 'name', 'description', 'custom_row_btn', 'dialog_url', 'async_load', 'dialog_lists') search_fields = ('name',)

def custom_row_btn(self, *args, **kwargs):
    # 从4.0开始 支持element-ui的组件
    return format_html(
        """
        <a href="javascript:;">查看详情</a>
        <el-button type="success" icon="el-icon-check" circle @click="$message('这是一条消息提示')"></el-button>
        <el-button type="danger" icon="el-icon-refresh" circle @click="app.refreshData()"></el-button>
        """)

custom_row_btn.short_description = 'elementui的组件'

以上代码双击后报错, list_editable = ['name', 'description']

发布评论
登录后发表内容
5个评论