I’ve tried numerous methods of finding the current user ID in django’s administration. I’ve tried pulling the user ID via SessionKey and request.user (HTTPRequest) to no avail. My latest incarnation is:
def save(self, request, obj, form, change):
if getattr(obj, 'submitter', None) is None:
obj.submitter = request.user
obj.save()
super(AppAdmin, self).save()
in admin.py and
submitter = models.ForeignKey(User, null=True, blank=True, related_name="submitter")
in models.py. I found this elsewhere on stack overflow, but it doesn’t seem to work. Any help is appreciated.
Thanks!
From the looks of your snippet, you are trying to save the currently logged in user to your model field in a
ModelAdminIt looks like you meant to override
save_modelhttp://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.ModelAdmin.save_model