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 6556629
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:58:08+00:00 2026-05-25T12:58:08+00:00

I have created a ModelForm class to be able to create and edit database

  • 0

I have created a ModelForm class to be able to create and edit database entries. Creating new entries works well, however, i dont know how to use ModelForms to edit/update an existing entry. I can instantiate a ModelForm with a database instance using:

form  = MyModelForm(instance=MyModel.objects.get(pk=some_id))

However, when i pass this to a template and edit a field and then try to save it, i create a new database entry instead of updating “some_id”?

Edit1:
This is my view

def editData(request):
if request.method == 'POST':
    form = MyModelForm(request.POST, request.FILES)

    if form.is_valid():
        editedEntry = form.save() # <-- creates new entry, instead of updating
  • 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-25T12:58:09+00:00Added an answer on May 25, 2026 at 12:58 pm

    Remember you still need to use the instance parameter when you instantiate on POST.

    instance = MyModel.objects.get(whatever)
    if request.method == "POST":
        form = MyModelForm(request.POST, instance=instance)
        ...
    
    else:
        form = MyModelForm(instance=instance)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a modelform that will either create a new model or edit an
I have a ModelForm where i give users a chance to create a new
I have created a C# class file by using a XSD-file as an input.
i have a Reply class: class Reply(models.Model): reply_to = models.ForeignKey(New) creator = models.ForeignKey(User) reply
I have a ModelForm that I have created a view and template with to
I have this model and modelform: class Comment(models.Model): text = models.CharField(max_length=100) def clean_text(self): print
I have the following model and it's form: class Project(models.Model) class ProjectForm(forms.ModelForm) class Meta:
I have a ModelForm field that is based on the following Model: class Phrase(models.Model):
I have a Modelform: class POwner4NewModel(ModelForm): class Meta: model = ProductOwner exclude = (o_owner,o_owner_desc,o_product_model,o_main_image,o_thumbnail,o_gallery_images,o_timestamp,o_status)
I have a form: class AdForm(ModelForm): class Meta: model = Ad widgets = {

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.