On Thu, Mar 4, 2010 at 3:08 AM, coco <geneviev...@gmail.com> wrote:
> Hello,
> Is it possible to get some kind of ListField() for some
> django.forms.Form fields ?
>
> Here is a typical example problem involving this. Let's try to make
> the following kind of form (forms.py):
>
> class mytable(forms.Form):
>    tags = forms.CharField()
>    x = forms.FloatField()
>    y = forms.FloatField()
>    z = forms.FloatField()
>
> Now, I want to link it with an editable html table like this (4
> columns x multiple rows):
>
> tags    x          y           z
> "pt1"   0.0       0.0       0.0
> "pt2"   1.3       2.1       5.0
> "pt3"   2.0       4.5       6.1
> and so on...
>
> The FloatField() in mytable() are inapropriates. One need some kind of
> FloatList() or TableGrid widget in order to stay DRY : I want to avoid
> hardcoding all the fields (x1,x2,x3,x4,x5,x6,... y1,y2,y3,...), but
> instead using some kind of (x[i], y[i], z[i]   or  data(i,j)). I can't
> figure how to do that. I do not want to use models, neither database
> system, but some direct handling like this snippet in views.py:
>
> def myfunct(request):
>    if request.method == 'POST':
>        form = mytable(request.POST)
>        if form.is_valid():
>            cd = form.cleaned_data
>            for i in range(len(cd['tags']))
>                print cd['x'][i] + cd['y'][i] + cd['z'][i]
>            f = mytable(cd)
>            return render_to_response('mytemplate.html', {'form': f})
>    else:
>        form = mytable()
>    return render_to_response('mytemplate.html', {'form': form})
>
> Does anyone know how to achieve this ? Thanks,
>

Use formsets [1].

Cheers

Tom

[1] http://docs.djangoproject.com/en/1.1/topics/forms/formsets/

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@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