Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

After Saving value in Positive Intefer filed Django Models, can not be edit later on

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")

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading