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

  • SEARCH
  • Home
  • 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 6841145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:55:50+00:00 2026-05-26T23:55:50+00:00

How do I update just one field in an instance using ModelForm if the

  • 0

How do I update just one field in an instance using ModelForm if the POST request has only that one field as parameter? ModelField tries to override the fields that were not passed in the POST request with None leading to loss of data.

I have a model with +25 fields say

class C(models.Model):
    a = models.CharField(max_length=128)
    b = models.CharField(max_length=128)
    ...
    x = models.IntegerField()

and I have a desktop application that does POST requests in order to edit an instance of C through an exposed api method in views.py

In the api method I am using ModelForm to validate the fields as follows:

form = CModelForm(request.POST, instance=c_instance)
if form.is_valid():
    form.save() 

When doing save() django either complains that some other field cannot be null or (if all fields are optional) overwrites them with None.

Does somebody know how to manage it? I would do all checks manually and update manually, but the model has so freakishly long list of fields…

  • 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-26T23:55:51+00:00Added an answer on May 26, 2026 at 11:55 pm

    You could use a subset of the fields in your ModelForm by specifying those fields as follows:

    class PartialAuthorForm(ModelForm):
        class Meta:
            model = Author
            fields = ('name', 'title')
    

    From the docs:

    If you specify fields or exclude when creating a form with ModelForm,
    then the fields that are not in the resulting form will not be set by
    the form’s save() method.

    https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#using-a-subset-of-fields-on-the-form

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

Sidebar

Related Questions

UPDATE: So pretty much everyone here has told me that I just need to
I just installed Eclipse Galileo for Java developers and noticed that the update site
Update: Last night, I decided that this is just too much work to change
How can I update an entity effectively in hibernate just as by using SQL.
Is it possible to achieve next thing without using views, but just one single
I am developing a wizard using Formwizard that matches one model. Also due to
I have an NSTableView that has one column of editable fields. Cell editing works
I just started using Datamapper. I am trying to update an object. I get
I have a DetailsView that looks just about perfect. The only thing is, there
Hey guys, I'm working on a status-Updater. It works, there is just one problem,

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.