I have a model Package with a field owner that should contain the user ID that has created the object instance. I thought about overriding the save() method but I didn't figure out how to get the logged in user. I have proceeded this way
class Package(models.Model):
source = models.CharField(max_length=20)
destination = models.CharField(max_length=20)
date_estimation = models.DateTimeField()
owner = models.ForeignKey('auth.User', related_name='packages', on_delete=models.CASCADE)
def save(self, *args, **kwargs):
#WAHT TO DO HERE ?
super(Package, self).save(*args, **kwargs)
How can I save the current logged in user ? Thank you