Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6824441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T21:54:07+00:00 2026-05-26T21:54:07+00:00

In my views.py I have something like this: a = Profile.objects.get(user=request.user.id) a.avatar = avatar.id

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T21:54:08+00:00Added an answer on May 26, 2026 at 9:54 pm

    Found out that the answer is NO.

    I used manage.py shell and 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:

    avatar = Avatar.objects.create(user = a_user)
    avatar.delete()
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have something like this in my views.py instance = get_object_or_404(register,pk=request.user.id) Now if there
I have something like this in one of my views <li <?php $isCurrent ?
I'm having some difficulties with Ajax.BeginForm I have something like this in a view
I have a View that renders something like this: Item 1 and Item 2
Generally, MVC frameeworks have a structure that looks something like: /models /views /controllers /utils
in my .aspx page i have something like this: <select id=seltemp onchange=calltemp()> <option value=0
Suppose I have something like this in my models.py: class Hipster(models.Model): name = CharField(max_length=50)
To get a one-off view on a Plone folder I do something like this
In my root template I have something like this {% if special %} some_special_html
I have many thousands of profile URLs that currently look like this: view_profile.php?id=12345 Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.