Let’s try to shift the perspective just a little. “Django”, as the web framework, doesn’t “know” (or “care”) what is calculated when - You do.
And so the questions are, when and where do you care?
If you only have one or two views that need to display this calculated field, then you can create a class method to prepare this value to be displayed.
Small example:
class CapacityRequest(models.Model):
...
diskspacegb = models.IntegerField(default=0)
def diskspace_gb_vswap(self):
return self.diskspacegb * 1.5
You can then directly reference that function in your templates as a value to be displayed in a manner similar to:
{{ some_capacity_request.diskspace_gb_vswap }}
(You can also use that method in your view if the value is needed for other calculations.)
If you’re going to need it for multiple rows at one time that you’re retrieving through a query, you can use the annotate method on the queryset to apply this calculation on every row being retrieved:
some_capacity_requests = CapacityRequest.objects.filter(...).annotate(
diskspace_gb_vswap=F('diskspacegb') * 1.5)
Finally, if you really wanted to get fancy with this, you could create a custom manager that adds this annotation to every query on that table.
So it really comes down to figuring out how much or how often you’re going to need that calculated value.
Ken