Hi Alex,

Thanks for your reply.  Yes, I had found and experimented with both
has_changed() and changed_data(), but I found that they don't deal as
I'd like with my case where my form contains fields that are not in
the model.   IE, using the Book example, if I have

model Book(models.Model):
  name = models.CharField()

model Author(models.Model)
  books =  models.ManyToManyField(Book)

If I create a BookForm that is like this, that allows the user to put
in the authors:

class BookForm(forms.ModelForm)
    authors = forms.CharField(widget=forms.Textarea,  help_text="space
separated list of authors")

    class Meta:
        model=Book

I find that changed_data() always returns 'authors' and has_changed is
always True.  I will take a look at the source a bit more.

Margie





On Feb 25, 4:59 pm, Alex Gaynor <alex.gay...@gmail.com> wrote:
> On Wed, Feb 25, 2009 at 7:55 PM, Margie <margierogin...@yahoo.com> wrote:
>
> > Say I create a form that reflects the current state of an object.  The
> > user can edit that form, and when they click 'save', I get back the
> > new, possibly edited, values via the POST.  In my POST code I do
> > something like this:
>
> > postDict = request.POST.copy()
> > bookForm = BookForm(postDict, instance=bookObj)
> > if bookForm.is_valid()
> >  bookForm.save()
>
> > What do folks typically do to avoid saving the data if nothing has
> > been modified in the form?  Is there any django functionality for
> > doing this, or do I just write the manual check that compares the
> > fields in the form to the fields in the existing object?
>
> > I'm not only concerned with the database access.  In addition to
> > avoiding the save, I'd like to emit a message to the user that
> > reflects what they've done, or not done.  IE, "book foo updated' or
> > "book foo unchanged".
>
> > Anyway, just curious if others have encountered this.
>
> > Margie
>
> > Form's have a method "has_changed" which says whether or not there is
>
> changed data, this should do just what you expect.
>
> Alex
>
> --
> "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
-~----------~----~----~----~------~----~------~--~---

Reply via email to