Re: Updating profile image in django

2022-12-29 Thread 'Adam Johnson' via Django developers (Contributions to Django itself)
Hi!

I think you've found the wrong mailing list for this post. This mailing
list is for discussing the development of Django itself, not for support
using Django. This means the discussions of bugs and features in Django
itself, rather than in your code using it. People on this list are unlikely
to answer your support query with their limited time and energy.

For support, please follow the "Getting Help" page:
https://docs.djangoproject.com/en/stable/faq/help/ . This will help you
find people who are willing to support you, and to ask your question in a
way that makes it easy for them to answer.

Thanks for your understanding and all the best,

Adam

On Mon, Dec 26, 2022 at 4:32 PM Nsikan Patrick 
wrote:

> 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
> 
> .
>

-- 
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/CAMyDDM0RuXhd5eR-hFmEtcwm9kesV8HCUPzJ27-GdgYbtMaRAg%40mail.gmail.com.


Updating profile image in django

2022-12-26 Thread Nsikan Patrick
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.