duanji1043 2017-04-24 21:11
浏览 45

如何使QoR模型中的字段为只读?

I have a data model:

type Epg struct {
    gorm.Model
    Uri     string `gorm:";not null;unique"`
    Prefix  string `gorm:"size:64;not null;default:''"`
    Etag    string
    Updated time.Time
    Status  bool `gorm:"default:true"`
}

I publish this data model in menu:

EpgResource := Admin.AddResource(&models.Epg{}, &admin.Config{Menu: []string{"Content"}})

Now I can view and edit data via QoR Admin panel. But I want to make values Etag, Updated, Status to be readonly because they are updated by the system.

If I try to make this fields readonly according documentation:

EpgResource.Meta(&admin.Meta{Name: "Etag", Type: "Readonly"})

I got an error. Is it possible to make some fields in data model visible but readonly? How to do that?

Error log trace.

2017/04/25 01:16:04 Finish [GET] /admin/epgs Took 19.59ms /usr/local/go/src/text/template/exec.go:433 /usr/local/go/src/text/template/exec.go:536 /usr/local/go/src/text/template/exec.go:668 /usr/local/go/src/reflect/value.go:302 /usr/local/go/src/reflect/value.go:434 /usr/local/go/src/runtime/asm_amd64.s:515 /home/rns/golang/src/github.com/qor/admin/func_map.go:1051 /home/rns/golang/src/github.com/qor/admin/func_map.go:220 /home/rns/golang/src/github.com/qor/admin/func_map.go:236 /home/rns/golang/src/github.com/qor/admin/func_map.go:393 got error when render form template for Etag(Readonly): haven't found form template for meta Etag

  • 写回答

2条回答 默认 最新

  • duanfu7840 2017-04-24 23:40
    关注

    That particular error is being caused by qor not finding a template file at .../metas/form/Etag.tmpl, which is presumably needed to actually render the Etag to the form. (You can make the template render a readonly/static element rather than an input)

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100