What is the advantage of using Django 5.0's GeneratedField to have the database calculate a field value versus doing it in the Python save() method?

Last updated 17 June 2026

  • A GeneratedField makes the database compute the value (as a stored or virtual column) on every insert/update, including bulk_create(), update(), raw SQL and other apps.

  • A save() override is silently skipped by ORM paths that don't call it, so derived data can drift. The generated column is also a real column you can filter, order and index.

  • Tradeoff: the expression may only use same-model fields and DB-supported functions (no complex Python logic). Choose db_persist=True (stored) or virtual based on backend support.

  • https://unfoldai.com/django-generatedfield/
  • https://stackoverflow.com/questions/77602793/django-5-0-how-generatedfield-actually-works
  • https://stackoverflow.com/questions/22157437/model-field-based-on-other-fields
All Django interview questions