You can do this either by submitting the form whenever the user field is changed or you can use Ajax to do this asynchronously. Both require a bit of JavaScript code. The first option requires that you use a modelform. The steps are pretty standard.
- Submit the user data
- Find the user in your database
- Load the user instance into your modelform
- Pass your form to the context variable
For Ajax, search for tutorials on Ajax and see this answer on SO.
In your HTML:
<select name="user_selector" id="userDropDown" class=" whatever-custom-css-class" autofocus onChange="this.form.submit();">
Then, inside your get requet, you can
user_name = self.request.GET.get('user_selector', None)
if user_name:
try:
selected_user = User.objects.get(username = user_name)
except ObjectDoesNotExist:
# No such user.
selected_user = None
if selected_user:
contact_form = ContactForm(instance = selected_user)
...
context.update({'form': contact_form})
return render(request, self.template_name, context)