Hello everyone, so I have I have this issue when trying to update a profile 
photo in django.
The Profile photo actually updates if I upload an image. But there are 
cases where a user may want to update other details without updating the 
profile photo.
Trying to implement that gives me a multivalue error.
I've been on this for some time now, who knows how I can handle that.
Here's my code on views.py file

def profile_update(request, user_id):
    if request.method == 'POST':
        user_obj = User.objects.get(id=user_id)
        user_profile_obj = UserProfile.objects.get(user=user_id)

        user_img = request.FILES['user_img']
        username = request.POST["username"]
        email = request.POST["email"]
        phone = request.POST["phone"]
        address = request.POST["address"]

        fs_handle = FileSystemStorage()
        img_name = 'uploads/profile_pictures/user_{0}'.format(user_id)
        if fs_handle.exists(img_name):
            fs_handle.delete(img_name)
        fs_handle.save(img_name, user_img)

        user_profile_obj.profile_pic = img_name
        
        user_profile_obj.phone = phone
        user_profile_obj.address = address
        user_profile_obj.save()
        
        user_obj.username =  username
        user_obj.email = email
        user_obj.save()
        user_obj.refresh_from_db()

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/ad3f98d1-c715-41e0-b05e-99e8be1f856cn%40googlegroups.com.
  • Upd... Nsikan Patrick
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to