so i want to create object from last_action on save of each models(Cars,Books,Carrots), but as far as i know instance is only passing attributes of sender model. So now i want to as well use user which is logged in, but i do not know how to pass it to my object, because sender model does not have it. How can i access to user and pass it to my object?
signals.py
@receiver(post_save,sender=Cars)
@receiver(post_save,sender=Books)
@receiver(post_save,sender=Carrots)
def Save_last_editor(sender,instance,**kwargs):
last_action.objects.create(item=instance.item,user = ???)
models/items.py
class Items(models.Model):
name = models.CharField(max_length=30, unique=True)
models/carrots.py
class Cars(models.Model):
name = models.CharField(max_length=30, unique=True)
item = models.ForeignKey('Item', on_delete=models.PROTECT)
models/carrots.py
class Books(models.Model):
name = models.CharField(max_length=30, unique=True)
item = models.ForeignKey('Item', on_delete=models.PROTECT)
models/last_action.py
class LastAction(models.Model):
item = models.ForeignKey('Item', on_delete=models.PROTECT)
user = models.ForeignKey('User', on_delete=models.PROTECT)
last_update = models.DateField(auto_now_add=True)