Thanks for your response Tim.  However, you lost me a bit there, I am
a real newbie.  I have narrowed my question down to this:

# in views.py:

class PropertyForm(ModelForm):
        class Meta:
                model = Property

def property_update(request, property_id='0', street_id='0'):
        print "data/property_save, request.method= ", request.method
        message = ''
        # we attempt to update an edit
        print "attempt to update"
        form = PropertyForm(request.POST)
        if form.is_valid():
                form.save()

        return render_to_response('wha/property_form.html', {'form': form,
'message': message})

My property_update function is called when the form Save button is
clicked.  The various "print" commands operate as expected.  However,
the validation fails and a form with no data is returned with
"required data" labels.  I conclude the line:
form = PropertyForm(request.POST)
does not populate the validation form.  What have I got wrong here?
TIA

Mike


On Jun 1, 8:14 pm, Tim Sawyer <list.dja...@calidris.co.uk> wrote:
> On Monday 01 June 2009 01:38:30 adelaide_mike wrote:
>
>
>
> > I found a really clear explanation of creating and updating database
> > objects in SAMS TeachYourself Django, but it appears to be for v
> > 0.96.
>
> > I have looked at "Creating forms from models" in the documentation,
> > and about one-third the way down it shows the following:
>
> > # Create a form instance from POST data.
>
> > >>> f = ArticleForm(request.POST)
>
> > # Save a new Article object from the form's data.
>
> > >>> new_article = f.save()
>
> > # Create a form to edit an existing Article.
>
> > >>> a = Article.objects.get(pk=1)
> > >>> f = ArticleForm(instance=a)
> > >>> f.save()
>
> > # Create a form to edit an existing Article, but use
> > # POST data to populate the form.
>
> > >>> a = Article.objects.get(pk=1)
> > >>> f = ArticleForm(request.POST, instance=a)
> > >>> f.save()
>
> > I understand what these code fragments are intended to do (I think)
> > but I am not clear as to how to use them.  Can someone point me to a
> > more fully displayed example?  TIA
>
> > Mike
>
> Here's an example from my code, does this help?
>
> Tim.
>
> def edit_result(request, pResultSerial):
>     """
>     Edit a single result row
>     """
>     lContestResult = get_object_or_404(ContestResult, pk=pResultSerial)
>     if request.user != lContestResult.owner:
>         raise Http404()
>     if request.method == 'POST':
>         form = ContestResultForm(request.POST, instance=lContestResult)
>         if form.is_valid():
>             form.save()
>             return
> HttpResponseRedirect(reverse('bbr.contests.views.single_contest_event',
> args=[lContestResult.contest_event.contest.slug,
> lContestResult.contest_event.date_of_event]))
>     else:
>         form = ContestResultForm(instance=lContestResult)
>
>     return render_auth(request, 'contests/edit_result.html', {'form': form,
> 'ContestResult' : lContestResult})
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to