如何使Django模型为只读? [英] How can I make a Django model read-only?

查看:83
本文介绍了如何使Django模型为只读?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将Django模型设为只读?没有创建,更新等。

Is it possible to make a Django model read only? No creating, updating etc.

N.B。这个问题不同于:

N.B. this question is different to:

将Django模型设为只读?(此问题允许创建新记录)

Make a Django model read-only? (this question allows creation of new records)

整个模型为只读(仅涉及Django管理界面-我希望该模型只能在整个应用程序中读取)

Whole model as read-only (only concerns the Django admin interface - I'd like the model to be read only throughout the whole app)

推荐答案

覆盖模型的保存和删除方法。您打算如何向模型中添加对象?

Override the save and delete methods for the model. How are you planning to add objects to your model?

def save(self, *args, **kwargs):
     return

def delete(self, *args, **kwargs):
     return

这篇关于如何使Django模型为只读?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆