Django model property for computed fields

2167
0

Properties let me add computed attributes to models without storing them in the database. I use @property for simple calculations like full name or age. For expensive computations, I consider caching the result in a field and updating it via signals or save override. Properties can't be used in QuerySet filters—use annotate() for that. I keep property logic simple and stateless. For display-only values, properties are cleaner than adding methods. They work seamlessly in templates and serializers, appearing just like regular fields.