将值保存为正整数提交Django模型后,以后再也无法编辑

发布于 2025-02-05 03:22:14 字数 214 浏览 2 评论 0原文

我正在django models.py上的Postive Integer字段工作,我想在保存后将其归档不变。保存值后不能是eidt。

模型

end_run = models.PositiveIntegerField(
    null=True, blank=True, help_text=_("Can be enter value Onece")

I am working on postive integer field on django models.py , I want to make that filed unchangeble after saving. Can not be eidt after saving value.

models.py

end_run = models.PositiveIntegerField(
    null=True, blank=True, help_text=_("Can be enter value Onece")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

燕归巢 2025-02-12 03:22:14

您是超级用户将始终能够更改它。
最后,您可以无需任何接口即可直接使用数据库更改它。

但是对于用户,您可以通过前端和后端的

方式限制他们:

def frontend_way(request):
    this_object = #get you object
    #check if this object has integer or not
    if this_object.end_run:
        flag_to_fronted = "this_integer_exist"
    else:
        flag_to_fronted = "this_integer_doesnt_exist"

在这种情况下,如果一个标志用户可以更改此整数,则可以通过标志操作,如果他不能

后续方式(验证):

def backend_way(request):
     this_object = #get_this_object
     #check if this object has integer or not
     if this_object.end_run:
          #this integer already exist, then return error or smth
     else:
          #this integer doesnt exist, and you can create it here

You are as super user will always be able to change it.
In the end you could change it directly with database without any interface.

But in case of the users, you can restrict them with fronted and, and backend

frontend way:

def frontend_way(request):
    this_object = #get you object
    #check if this object has integer or not
    if this_object.end_run:
        flag_to_fronted = "this_integer_exist"
    else:
        flag_to_fronted = "this_integer_doesnt_exist"

in this case you can operate via a flag if one flag user can change this integer, if another he can't

backend way (validation):

def backend_way(request):
     this_object = #get_this_object
     #check if this object has integer or not
     if this_object.end_run:
          #this integer already exist, then return error or smth
     else:
          #this integer doesnt exist, and you can create it here
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文