Open jordanmkoncz opened 8 years ago
For additional context, the code where I'm attempting to do this is part of a Django api_view
, which looks like this:
@api_view(['POST'])
@authentication_classes([permissions.IsAuthenticated])
def submit_model_a(request, format=None):
# Code handling ModelA submission
user = model_a_record.user
model_b_record.modified_by = user
model_b_record.save()
# Code handling returning a response
I'm wondering whether perhaps the issue is that django-audit-log
's UserLoggingMiddleware
is coming in to play when I try to save the ModelB
record and is basically overwriting the modified_by
value with None
.
In my application I have a model, let's call it
ModelA
, which does not use theAuthStampedModel
mixin. I have another model,ModelB
which uses theAuthStampedModel
mixin.Part of the functionality of my application includes handling a
POST
request that makes an update to aModelA
record, and then also makes an update to an associatedModelB
record (based on application-specific business logic). When I make the update to theModelB
record I want itsmodified_by
value to be set to the user who triggered the update to theModelA
record which then led to also updating theModelB
record.However I'm stuck on how I would accomplish this. I've tried doing the following:
However this attempt to manually update
modified_by
does not work. I assumed this would be becausemodified_by
is aLastUserField
which has a default ofeditable=False
, but even after creating my ownEditableAuthStampedModel
where themodified_by
field is set to aLastUserField
with an explicit value ofeditable=True
, themodified_by
value that I manually set does not get saved.Any ideas?