79278650

Date: 2024-12-13 14:35:27
Score: 1
Natty:
Report link

A nice way to do it inside the model and with no query to the db is to override the init method of the model

class CustomModel(models.Model):
    count = models.IntegerField()

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._original_count = self.count

    def clean(self):
        value = self._original_count
        ...
Reasons:
  • Has code block (-0.5):
  • Unregistered user (0.5):
  • Low reputation (1):
Posted by: Stan Baumer