Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » Django
  • » missing default values in formfields.FormWrapper(...) [RSS Feed]

#1 Dec. 4, 2005 23:17:48

E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

missing default values in formfields.FormWrapper(...)


Dear djangonauts,
I'm playing with formfields and manipulators: wonderful! But I'm
missing one thing: following docs on Forms and Manipulators I'm not
able to put model's default values to fill forms in the proper way.

Consider the last example of "Using the AddManipulator" subsection:
------------
def create_place(request):
manipulator = places.AddManipulator()
if request.POST:
# If data was POSTed, we're trying to create a new Place.
new_data = request.POST.copy()
........(cut).........
else:
# No POST, so we want a brand new form without any data or
errors.
errors = new_data = {}
# Create the FormWrapper, template, context, response.
form = formfields.FormWrapper(manipulator, new_data, errors)
return render_to_response('places/create_form', {'form': form})
---------------
from what is written, when create_place is called with no POST data,
the "form" has new_data={}, so default values are missing (assume that
Place has some explicit default values in the model).
I'd like to use model's default values in that form, basically filling
new_data={} automagically from model's definitions. How can I do it?
Right now I'm only able to do it "by hand", like writing explicitely
new_data={'city':'NoWhere', 'zip_code':'12345'} instead of new_data={},
which is not so nice.

Thanks in advance for every ideas/suggestions to solve this problem,

Emanuele

Note: my request looks like in some way to Bryan Murdock's request
(unanswered):http://groups.google.it/group/django-users/browse_thread/thread/e97eeed0b3256564/355a55a1ff7e4a61?q=form+default+values&rnum=1#355a55a1ff7e4a61

Offline

#2 Dec. 5, 2005 00:16:15

Pedro F.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

missing default values in formfields.FormWrapper(...)


    else:        # No POST, so we want a brand new form without any data orerrors.        errors = new_data = {}Copy from the admin view:    else:        # Add default data.        new_data = manipulator.flatten_data()        # Override the defaults with
request.GET, if it exists.        new_data.update(request.GET)        errors = {}Hope it works.Bye--Pedro

Offline

#3 Dec. 5, 2005 09:48:57

E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

missing default values in formfields.FormWrapper(...)


Thanks a lot! It works perfectly. I think this should go in 'Forms and
Manipulators' docs as soon as possible!

Emanuele

Offline

#4 Dec. 6, 2005 00:08:16

E.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

missing default values in formfields.FormWrapper(...)


Maybe this is relevant for those interested in the thread:
manipulator.flatten_data() is available only on recent SVN version of
Django. It is unfortunately NOT available in Django_0.90.

Cheers,

Emanuele

Offline

#5 Dec. 7, 2005 07:51:56

Bryan M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

missing default values in formfields.FormWrapper(...)


On 12/4/05, Pedro Furtado <> wrote:
>
> > else:
> > # No POST, so we want a brand new form without any data or
> > errors.
> > errors = new_data = {}
> >
>
> Copy from the admin view:
>
> else:
> # Add default data.
> new_data = manipulator.flatten_data()
>
> # Override the defaults with request.GET, if it exists.
> new_data.update(request.GET)
> errors = {}
>
> Hope it works.

I just did an svn up. Lo and behold, my related problem has
disappeared. It seems the generic views now do this for me, like they
should. Yay.

Bryan

Offline

  • Root
  • » Django
  • » missing default values in formfields.FormWrapper(...) [RSS Feed]

Board footer

Moderator control

Enjoy the 20th of January
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support