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")
CodePudding user response:
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