List Info

Thread: Re: Solution: change only a subset of a model's field in newforms




Re: Solution: change only a subset of a model's field in newforms
user name
2007-02-28 10:25:10
On 2/28/07, akaihola <akaiholagmail.com> wrote:
>
> It must be a common need to allow the user to change
only some fields
> of an object and keep old values for the rest.
>
> So far with newforms this has involved copying values
explicitly from
> the database object to the form object. Looking at
newforms code I
> realized that a cleaner way is to just not try to copy
missing fields
> from the form object to the database object before
saving.
>
> For one possible solution, see http://akaihola.blogspot.com/2007/02/django
-newforms-improvement.html
> for details and the code.
>
> The code is based on newforms.models and makes minimal
changes to
> form_for_instance (and its helper functions) to achieve
the new
> functionality.
>
> If this new behaviour doesn't violate the intentions
behind newforms,
> could it be adapted into Django?

I've written similar code, and that functionality definitely
belongs
in Django. The best way to get it considered for inclusion
is to file
a patch with docs and tests. You may want to propose the
syntax on
django-developers first, however.

http://www.djangoproject.com/document
ation/contributing/#submitting-patches

Joseph

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: Solution: change only a subset of a model's field in newforms
user name
2007-02-28 10:36:55
On 2/28/07, Joseph Kocherhans <jkocherhansgmail.com> wrote:
>
> On 2/28/07, akaihola <akaiholagmail.com> wrote:
> >
> > It must be a common need to allow the user to
change only some fields
> > of an object and keep old values for the rest.
> >
> > So far with newforms this has involved copying
values explicitly from
> > the database object to the form object. Looking at
newforms code I
> > realized that a cleaner way is to just not try to
copy missing fields
> > from the form object to the database object before
saving.
> >

Similarly from a non-autogenerator standpoint there is
currently no
method for taking data in an instance of an object and
passing that to
the form for initialization.  The best we could come up with
that
using object_instance.__dict__ and then feeding in by hand
foreign
fields and manyToMany fields.

Perhaps what we need is really a more abstracted function
that would
allow for similar syntax to what was proposed but works
independant of
the auto-generator functions.

something like a object_instance.values(include =
('content',))

which could then be utilized by the autogenerators to
provide that
same functionality while offering to those of us who don't
fit the
auto-gen mold, to be able to have similar functionality.

~ Anders

> > For one possible solution, see http://akaihola.blogspot.com/2007/02/django
-newforms-improvement.html
> > for details and the code.
> >
> > The code is based on newforms.models and makes
minimal changes to
> > form_for_instance (and its helper functions) to
achieve the new
> > functionality.
> >
> > If this new behaviour doesn't violate the
intentions behind newforms,
> > could it be adapted into Django?
>
> I've written similar code, and that functionality
definitely belongs
> in Django. The best way to get it considered for
inclusion is to file
> a patch with docs and tests. You may want to propose
the syntax on
> django-developers first, however.
>
> http://www.djangoproject.com/document
ation/contributing/#submitting-patches
>
> Joseph
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "Django users" group.
To post to this group, send email to django-usersgooglegroups.com
To unsubscribe from this group, send email to
django-users-unsubscribegooglegroups.com
For more options, visit this group at htt
p://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )