I am using Django 1.8 and I am trying to implement a simple logging to a model. I have overridden the save method of the class. However, I also want to log which user is responsible for the change but the request object is not available since it's not passed into the save method. I don't want to pass the user in all occurrences of the save method because I am using django-rest-framework.
Here is my code:
def save(self, *args, **kwargs):
order = super(Order, self).save(*args, **kwargs)
try:
json_object = serializers.serialize('json', [ order, ])
# I want to log the current user too.
OrderLog.objects.create(order = order, object = json_object)
except Exception as e:
print e
return order