Friday, May 20, 2011

multiple instances of form (with distinctive identifiction) on same page?

hi there, first poster and django beginner here..

I've been unsuccessfully looking for an answer to this for a while
now, so I'm finally posting it myself.

I'm writing an app that allows users to place bets on soccer matches.
several matches are listed on the same site consisting each of two
opposing teams and a form (basically two fields to enter score) to
place a bet.
this is where I ran into issues. I need multiple instances of the same
form on one page that can be distinctively identified.

1st attempt:
I just pass my form from the view and let the template render multiple
instances using a for-loop.
Problem:
The forms lack a unique identifier.
> not a problem when saving since I am passing the match id in a hidden field. but if validation errors occur it sends them back to the respective field of all forms instead of just the one where an error happened.

2nd attempt:
using 'prefix', I create a form for each match with its own prefix in
the view and collect them in a list to pass to the template.
Problem:
In the template I cannot iterate over the list items using a variable
but have to use the explicit index numbers which I want to avoid since
the number of forms needed may vary.

any suggestions on how I could approach this?

really appreciate all feedback, thanks in advance.
pascal

--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate