About Model Methods and their Access in Templates

For all Django model methods that change the database entries anyhow, add an attribute alters_data = True. This ensures that the method cannot be called from a template.

For example:

1
2
3
def calculate(self):
    # does some calculations and saves them
calculate.alters_data = True

Tips and Tricks Programming Django 4.2 Django 3.2 Django 2.2