How can I create Generated/Computed column Postgres/DJANGO?
I tried in both ways:
(1) By a Class:
class Product(models.Model):
name = models.CharField(max_length=200, null=True)
precio_costo = models.FloatField(null=True)
cantidad = models.IntegerField(null=True)
monto_stock = models.FloatField(
always_generated='precio_costo * cantidad', stored=True)
ERROR I GET:
TypeError: init() got an unexpected keyword argument 'always_generated'
(2) Directly by POSTGRES Admin
But I can't update or add a new field, Default value is required by Django.
In Django >5.0 you can use GeneratedField.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With