I want to use abstract model to have all my common fields. How do I auto populate updated by. ?
I saw some old answers saying it is not possible to do in the model . DRY way to add created/modified by and time
Anything changed+ in 5 years?
So far it looks like most easy way is to use both decorator django-author with Common model for other fields.
from author.decorators import with_author
@with_author
class CommonInfo(models.Model):
created = models.DateTimeField("creation date", auto_now_add=True)
modified = models.DateTimeField("modification date", auto_now=True)
description = models.TextField()
is_active = models.BooleanField(default=True)
class Meta: and to have more control
abstract = True
But the problem is that if I add decorator to abstract model I am getting error
unit.Unit.updated_by: (fields.E305) Reverse query name for 'Unit.updated_by' cla shes with reverse query name for 'Tenant.updated_by'. HINT: Add or change a related_name argument to the definition for 'Unit. updated_by' or 'Tenant.updated_by'.
To avoid it I have to add the decorator to each model instead .
Is it possible to add the decorator to Abstract model somehow without getting this error?