I need to pass in the name of the user, so that I can set the user_name in the service model in the html. Should I even be setting default values in the html? If not, how would I do this in the view? I don't want the username field to appear in the form (I've already taken care of that) I want it to be updated in the background when the user clicks the 'create service' button.
here is my views.py file:
def create(request):
# val= 3
if request.POST:
form= ServiceForm(request.POST)
if form.is_valid():
# form.fields['zipcode'].initial = val
service_obj = form.save()
return render_to_response('services/service_created.html',
{'service': Service.objects.get(id=service_obj.id)})
else:
form = ServiceForm()
args= {}
args.update(csrf(request))
args['form'] = form
active_user = request.session['active_user'] = request.user.username
#The line below doesn't work how I would like it to
return render_to_response('services/create_service.html', {'args': args, 'user': active_user} )
Here is my create_service.html
<form action="/services/create" method="post" enctype="multipart/form-data">{% csrf_token %}
<ul>
{{form.as_p}}
</ul>
<input type="submit" name="submit" value="Create Service">
</form>