Making a django model field readonly

I am creating a django DB model and I want one the fields to be readonly. When creating a new object I want to set it, but later if someone tries to update the object, it should raise an error. How do I achieve that?

I tried the following but I was still able to update the objects.

from django.db import models as django_db_models


class BalanceHoldAmounts(django_db_models.Model):
    read_only_field = django_db_models.DecimalField(editable=False)

Thank you

You can override it in the "save" method of the model and raise Validation Error if someone tries to update that field.

Back to Top