Error fields were all empty. I checked methods non_field_errors and _get_errors; _errors was None.
But Alex Gaynor was right! When I added the form "POST" data in, the form validated. I assumed that creating a ModelForm from an existing instance would give it valid data, but that's not the case. (Though the Django Documentation doesn't say this: http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ ) On Mar 24, 12:15 pm, David Zhou <da...@nodnod.net> wrote: > If it's not valid, then something likely threw a validation error. > What does the error say? > > -- dz > > On Tue, Mar 24, 2009 at 3:11 PM, Theme Park Photo, LLC > > <swir...@gmail.com> wrote: > > > It has data! It was created from an existing instance...and all the > > fields have values > > > 'body': u'<p>hello there</p>', 'allow_comments': > > 1, 'author': 10L, 'tease': u'<p>hello there</ > > p>', > > 'publish': datetime.datetime(2009, 3, 23, 15, > > 3, > > 36), 'score': -93L, 'categories': [1L], > > 'title': > > u'Hello', 'slug': u'hello-0', 'tags': > > u'hello'} > > > On Mar 24, 12:06 pm, Alex Gaynor <alex.gay...@gmail.com> wrote: > >> On Tue, Mar 24, 2009 at 3:02 PM, Theme Park Photo, LLC > >> <swir...@gmail.com>wrote: > > >> > Im trying to get code to edit an existing record in a table working. > >> > For some reason, form.is_valid is returning false (and I can't save it > >> > because there's no cleaned data). Even reduced to this (below) where > >> > I'm simply getting an existing "Post" object, creating a ModelForm, > >> > and validating it, fails! > > >> > Any suggestions? > > >> > post = Post.objects.get(id=postId) > >> > form = PostForm(instance=post) > >> > if form.is_valid(): # All validation rules pass > >> > form.save() > >> > else: > >> > # at this point, non_field_errors and _get_errors > >> > return null. _errors is defined as none(), yet form.is_valid > >> > # is returning false > > >> A form without data is never considered valid. You probably want your > >> workflow to be more like: > > >> obj = Model.objects.get() > >> if request.method == 'POST': > >> form = Form(request.POST, isntance=obj) > >> if form.is_valid(): > >> form.save() > >> else: > >> form = Form(instance=obj) > >> return render_to_response() > > >> -- > >> "I disapprove of what you say, but I will defend to the death your right to > >> say it." --Voltaire > >> "The people's good is the highest law."--Cicero --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---