In my views.py I have something like this:
a = Profile.objects.get(user=request.user.id)
a.avatar = avatar.id
a.save()
From what I know when I do a save() if there is already a record with that specific user id it should just update the existing record with the avatar.id.
I’m not sure why but when I run the above code the existing record gets deleted. Am I doing this right?
Found out that the answer is NO.
I used
manage.py shelland ran the above code and it didn’t not delete the record. But I found out that another code above it was doing the damage.I had something like this:
The Profile model has a foreign key relationship with the Avatar. So when I did avatar.delete() when I thought it only deleted the record for the Avatar model it also deleted related Profile record.