THE GOAL: Display a request-specific, read-only user_id
on a django admin form when creating and updating a resource.
This display should be a readonly field (readonly, NOT disabled). The user_id
displayed is derived from the requesting user (request.user
) so the initial value is set from that.
Following this post, we should simply set it in the get_form
method like so:
def get_form(self, request, obj=None, *args, **kwargs):
form = super(ProfileAdmin, self).get_form(request, *args, **kwargs)
form.base_fields['user'].initial = request.user
return form
However, user is no longer on the base_fields
when it is readonly. In fact, I can't find it anywhere. Any thoughts?
Other posts suggest on save, which I intend to do, but I need it to show on the form before then.