'Django user updates profile picture and the other users receive this changes too

I created a form so that every user can update its profile. What it's happening is that when a user changes the profile picture of its account, also it changes the profile picture of the other users and of course, I don't want that. This is my code:

signals.py

def create_user_profile(sender, instance, created, **kwargs):

    if created:
        profile = Profile(user=instance)
        profile.save()

post_save.connect(create_user_profile,
                  sender=User,
                  dispatch_uid="profilecreation-signal")

forms.py

class ProfileForm(forms.ModelForm):
    class Meta:
        model = Profile
        fields = [
            "first_name",
            "last_name",
            "image",
            "description",
            "website"
        ]

views.py

def profile_page(request, username):
    form = ProfileForm(data=request.POST, files=request.FILES, instance=request.user.profile)

    if request.method == "POST":
        if form.is_valid():
            form.save()
            return redirect(request.META['HTTP_REFERER'])
    context = {
     
        "profile_form": form,
    }
    return render(request, "profile.html", context)

models.py

class Profile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    first_name = models.CharField(max_length=30, blank=True, null=True)
    last_name = models.CharField(max_length=30, blank=True, null=True)
    image = models.ImageField(default="default.jpg", upload_to="profile_pics")
    description = models.TextField(default=None, max_length=255, blank=True, null=True)
    website = models.URLField(max_length=255, blank=True, default="")

The profile_page view has username also as attribute because there is more code related to it.

Could someone help me? Thanks!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source