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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:59:32+00:00 2026-05-28T17:59:32+00:00

I want to have a bound form from an object to use the is_valid

  • 0

I want to have a bound form from an object to use the is_valid method. The reason is because I have some old data that I want the users to correct according to the new validation rules. Then, I want to reuse the code of the clean methods in my form.

I ended up serializing my response:

from django.utils import simplejson
from django.core.serializers import serialize

(...)

fields_dict = simplejson.loads(serialize('json', [obj]))[0]['fields']
form = forms.MyForm(fields_dict)
if form.is_valid

This works but it doesn’t seem very Djangish. Also, it seems as a common problem so I was looking for a better way of doing this.

According to the documentation, translating data from an unbound form to a bound form is not meant to happen:
https://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method
However, that would be the easiest solution for me.

  • 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-28T17:59:33+00:00Added an answer on May 28, 2026 at 5:59 pm

    There is Django’s django.forms.models.model_to_dict function that will convert your existing model instance into a dictionary of data suitable for binding to a ModelForm.

    This would probably be more efficient, and definitely more “Djangish”, than serialising and unserialising the object.

    And if you also create the form with the instance keyword, it will know to update the existing record when saved.

    So:

    from django.forms.models import model_to_dict
    
    ...
    
    fields_dict = model_to_dict(obj)
    form = forms.MyForm(fields_dict, instance=obj)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I have a form that I want the user to use to update
So I have an input form that I want to use to update a
I have a SQLDataSource that is bound to a ListView control but I want
I have a ListBox that is bound to a list of Persons. I want
I have a form that will be populated by a bunch of information from
I have a WPF / XAML form data-bound to a property in a dictionary,
I have a listbox on my xaml form that I bound to a List(Of
I have a form showing a gridview. The data is bound dynamically, depending on
I want to have an image bound to a boolean and have the source
I have a DataGridView bound to a LINQ to SQL query expression. I want

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.