On Sunday, January 30, 2011 8:02:08 AM UTC, gintare wrote:
> Is it possible by making small change to resolve the error below:
> (I did not yet finished reading all manual, maybe the error disappears
> if i make custom code for every line in the model, but my model has
> over 30 fields thus i would like to have automated save and post of
> all these fields)
>
> Django Version: 1.2.4
> Exception Type: AttributeError
> Exception Value: 'WordFormM' object has no attribute 'cleaned_data'
> Exception Location: c:\Python27\lib\site-packages\django\forms
> \models.py in save_m2m, line 78
>
> ###################views.py
> from forms import FindWordM
> from models import Word
> from django.shortcuts import render_to_response,
>
> def first(request):
> w=Word.objects.get(pk=90);
> formWord=WordFormM(instance=w);
> formWord.save();
> return render_to_response("c:/Python27/Scripts/Finnish2/Fin/
> templates/trials/correct.html", {
> "formWord": formWord})
>
>
> ###################forms.py
> from django.forms import ModelForm
> from models import Word
>
> class FindWordM(ModelForm):
> class Meta:
> model=Sent
>
> ###################models.py
> from django.db import models
>
> class Word(models.Model):
> WordSentences=models.TextField(max_length=1000,
> blank=True,default='')
> WordSentencesMM=models.ManyToManyField('self', null=True,
> blank=True)
> WordGramNotesDeclFK=models.ForeignKey(WordDeclN,
> related_name='DeclNWord', null=True, blank=True)
> ...
>
> ###################urls.py
> from django.conf.urls.defaults import *
>
> urlpatterns = patterns('',
> (r'^first','Finnish2.Fin.views.first')
> )
>
It's not very likely to encourage people to help you if you admit you
haven't read the documentation.
What exactly are you trying to do here? You instantiate a form from an
instance, and immediately try and save it, without even passing in values
from the POST. Why? In any case, the error is that forms don't have a
cleaned_data attribute until you call is_valid() on them, which the
documentation does clearly state. The documentation also shows the correct
pattern for using forms in views, so I don't know why you haven't used that.
(Not related to your problem, but the template path in your call to
render_to_response won't work: you should pass a path that is relative to
one of the paths in settings.TEMPLATE_DIRS.)
--
DR.
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.