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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:24:24+00:00 2026-06-12T09:24:24+00:00

Today I started reading the documentation for django.forms . The API seems easy to

  • 0

Today I started reading the documentation for django.forms. The API seems easy to use and I started experimenting with it. Then I started experimenting with django.forms.ModelForm but I cannot really see where I went wrong.

My problem starts here: the save method when creating a form with an instance.

My model is

class Process(models.Model):
    key         = models.CharField(max_length=32, default="")
    name        = models.CharField(max_length=30)
    path        = models.CharField(max_length=215)
    author      = models.CharField(max_length=100)
    canparse    = models.NullBooleanField(default=False)
    last_exec   = models.DateTimeField(null = True)
    last_stop   = models.DateTimeField(null = True)
    last_change = models.DateTimeField(null = True, auto_now=True)

and my form is

class ProcessForm(ModelForm):
    class Meta:
        model  = Process
        fields = ('name', 'path', 'author')

I only wanted the name, path and author fields since the other ones are automatically set when saving the model. Anyway, in my test database I already have entries and I’ve chosen one whose fields are all set and valid.

In the documentation you can read:

# Create a form to edit an existing Article.
>>> a = Article.objects.get(pk=1)
>>> f = ArticleForm(instance=a)
>>> f.save()

Very well, I wanted to do the same with my own code:

>>> from remusdb.models import Process
>>> from monitor.forms import ProcessForm
>>> 
>>> proc = Process.objects.get(name="christ")
>>> pf = ProcessForm(instance=proc)
>>> pf.save()
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/home/shaoran/devpython/lib/python2.6/site-packages/django/forms/models.py", line 364, in save
    fail_message, commit, construct=False)
  File "/home/shaoran/devpython/lib/python2.6/site-packages/django/forms/models.py", line 87, in save_instance
    save_m2m()
  File "/home/shaoran/devpython/lib/python2.6/site-packages/django/forms/models.py", line 78, in save_m2m
    cleaned_data = form.cleaned_data
AttributeError: 'ProcessForm' object has no attribute 'cleaned_data'
>>> pf.is_bound
False
>>> pf.is_valid()
False

Even though proc is a valid Process object the form object doesn’t seem to agree with me. If I do as the next example

>>> post = { "name": "blabla", "path": "/somewhere", "author": "me" }
>>> pf = ProcessForm(post, instance=proc)
>>> pf.is_bound
True
>>> pf.is_valid()
True
>>> pf.cleaned_data
{'path': u'/somewhere', 'name': u'blabla', 'author': u'me'}

then it works like in third example of the documentation.

Am I missing something or is there an error in the documentation? Or is my Model code somewhat wrong?

This is the content of proc

proc.dict
{‘name’: u’christ’, ‘last_stop’: datetime.datetime(2012, 10, 5, 16, 49, 13, 630040, tzinfo=), ‘author’: u’unkown’, ‘_state’: , ‘canparse’: False, ‘last_exec’: datetime.datetime(2012, 10, 5, 16, 49, 8, 545626, tzinfo=), ‘key’: u’aed72c9d46d2318b99ffba930a110610′, ‘path’: u’/home/shaoran/projects/cascade/remusdb/test/samples/christ.cnf’, ‘last_change’: datetime.datetime(2012, 10, 5, 16, 49, 13, 631764, tzinfo=), ‘id’: 5}

  • 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-06-12T09:24:25+00:00Added an answer on June 12, 2026 at 9:24 am

    The first argument to the form class is a dictionary that contains values that you want the form to validate.

    Since you never pass these values in, the form cannot validate any input; which is why cleaned_data is none. Since .save() triggers form and model validation, the form validation fails.

    You’ll notice the form actually has no data:

    af.data will be {} (empty dict)
    af.is_bound will be False (as you haven’t bound the form to any data)

    Since there is no data, validation fails. The error is a bit misleading. If you pass in an empty dict:

    af = ArticleForm({},instance=a)
    af.save()
    

    You’ll get a more appropriate error:

    ValueError: The Article could not be changed because the data didn't validate.

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

Sidebar

Related Questions

I started reading 'Introduction to Algorithms' today, but I've gotten a bit confused over
I started reading up about the NSFetchedResultsController today, but I've come across some confusing
I started experimenting with the MySQL C API today, which I compiled today from
I started reading about underscore.js today, it is a library for javascript that adds
I just started learning ASP.NET MVC4 today. After reading tutorials, downloading VS 2012, and
I am very new (started today) to writing chrome extensions but need to write
I just started C# today, and i have trouble reading an excel file. Here's
I've just started learning Python today. I've been reading a Byte of Python. Right
I was reading today about researchers discovering that NVidia's Phys-X libraries use x87 FP
Today I started experimenting with PHP-based PDF generators. I tried TCPDF and it works

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.