I have the following abstract class:
class UserStamp(models.Model):
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True,
related_name='%(app_label)s_%(class)s_created_by', on_delete=models.CASCADE)
updated_by = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,
related_name='%(app_label)s_%(class)s_updated_by', on_delete=models.CASCADE)
class Meta:
abstract = True
I have a custom User that inherits from User.
class User(AbstractBaseUser,PermissionsMixin, UserStamp):
account = models.ForeignKey(Account, blank=True, null=True, related_name='owner',on_delete=models.CASCADE)
The User can create/update himself or by other user.
When the user create/update himself I don't have anything for created_by, update_by.
The user can be created using Django Admin or outside Django Admin;
In Django Admin the user can be created by staff, outside Django is self created;
Also there is superuser that is created in terminal;
Regarding the update the user in both Django Admin and outside can be self updated or by another user.
I thought on using post_save or a custom signal. The issue is that request.user is not available in the model, but in View, and controlling the View in Admin and also in terminal(superuser) is a bottleneck.
Maybe trying to do a query after save passing the instance, but I don't exactly know how to combine all of them signal/query, check superuser.