If you're using the newest postgres 12, you could also use their new generated column feature ( https://www.postgresql.org/docs/current/ddl-generated-columns.html). You can implement that in Django by editing the SQL in the migration setting up your table. Though I do look forward to this feature being integrated more directly into Django as a postgres-specific option, prly won't be too long until it's incorporated.
On Monday, 21 October 2019 14:05:04 UTC-4, Eileen Bauer wrote: > > Hi, > i have the following items in my model: > mother_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, > null=True, default=1) > father_alive = models.IntegerField(choices=YES_NO_CHOICES, blank=True, > null=True, default=1) > > and I'd like to set up a generated field for them so I'd be able to detect > whether the child is an orphan or not. In MySQL i believe it'd look like > this: > orphan varchar(101) GENERATED ALWAYS AS (mother_alive+father_alive) > VIRTUAL, > > I don't know how to change my model to do that... > > Any help? > > -Eileen > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/68c3b9cb-b3ad-4f83-a834-74051441a0d8%40googlegroups.com.

