Working out editing profiles and ran into a little trouble! The following piece of code succesfully updates the mug_shot column in the user profile, but also erases all the other column data for that particular record. It's weird because Django is supposed to automatically distinguish between updates/saves. What's weirder is that everywhere else updates/saves seem to work fine.
I'm kind of at a loss.
@login_required
def add_mugshot(request):
user = request.user
profile = UserProfile.objects.get(user=user)
if request.method == 'POST':
profile_form = ProfileForm(request.POST, request.FILES, instance=profile)
if profile_form.is_valid():
new_profile = profile_form.save(commit=False)
new_profile.user = user
new_profile.save()
return HttpResponseRedirect('/accounts/profile/')
else:
profile_form = ProfileForm(instance=profile)
return render_to_response('accounts/add_mugshot.html',
RequestContext(request, {
'profile_form': profile_form}))