Re: newforms and many objects instances

2007-12-24 Thread lispingng

I have had a similar problem (prolly still do).
I actually used code like this

ResultForm = forms.form_for_model(Result)

result_forms = []
for i in range(num_forms):
form = ResultForm(prefix=str(i))
result_forms.append(form)

which will convert names of each form's widget like this;
name='student1' => name='1-student1', etc...
then, when i get the request.POST, i just collect all the post-data to
list of dictionaries and
use bind to forms.
on second thoughts, i think maybe i should have only one form to
contain multiple forms
and handle all this transparently in the form.
take a look at
http://eggdrop.ch/blog/2007/02/15/django-dynamicforms/
though he uses javascript to generate the forms client-side, should
give some ideas.
haven't gone through it myself (maybe that's why i have not done mine
yet:))
pls let me know how it goes
happy holidays!!!

On Dec 23, 7:34 pm, Chaves <[EMAIL PROTECTED]> wrote:
> Dear Sirs:
>
> I have this model
>
> class Student(models.Model):
>          name = models.CharField(max_length=50)
>
> class StudentGroup(models.Model):
>          name = models.CharField(max_length=20)
>          student = models.ForeignKey(Student)
>
> class Subjects(models.Model):
>          name = models.TextField()
>          studentgroup= models.ForeignKey(StudentGroup)
>
> class ExamScore(models.Model):
>         name = models.CharField(max_length=20)
>         examdate = models.DateField()
>         student = models.ForeignKey(Student)
>         subject = models.ForeignKey(Subject)
>         score = models.CharField(max_length=5)
>
> Im looking for a way to generate this form:
> ---
> Exam:__  (input text)
> Date:_(input text)
> Subject:_ (select)
>
> Student nº 1:(input text)
> Student nº 2:(input text)
> Student nº 3:(input text)
> Student nº 4:(input text)
> Student nº 5:(input text)
> Student nº 6:(input text)
>
> Save
>
> ---
>
> i know a way to do that in the classical process: send to the template two
> lists:
> (subjectList=Subject.object.filter(studentgroup="groupA")); and
> (studentList=
> StudentGroup.objects.filter(name="groupA")). The form in rendered in the
> template.
>
> My main propose is to do that using newforms. Anybody can help?
>
> Thanks a lot and Happy Christmas.
> --
> View this message in 
> context:http://www.nabble.com/newforms-and-many-objects-instances-tp14479408p...
> Sent from the django-users mailing list archive at Nabble.com.
--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---



newforms and many objects instances

2007-12-23 Thread Chaves


Dear Sirs:

I have this model

class Student(models.Model):
 name = models.CharField(max_length=50)

class StudentGroup(models.Model):
 name = models.CharField(max_length=20)
 student = models.ForeignKey(Student)

class Subjects(models.Model):
 name = models.TextField()
 studentgroup= models.ForeignKey(StudentGroup)

class ExamScore(models.Model):
name = models.CharField(max_length=20)
examdate = models.DateField()
student = models.ForeignKey(Student)
subject = models.ForeignKey(Subject)
score = models.CharField(max_length=5)

Im looking for a way to generate this form:
---
Exam:__  (input text)
Date:_(input text)
Subject:_ (select)

Student nº 1:(input text)
Student nº 2:(input text)
Student nº 3:(input text)
Student nº 4:(input text)
Student nº 5:(input text)
Student nº 6:(input text)

Save

---

i know a way to do that in the classical process: send to the template two
lists:
(subjectList=Subject.object.filter(studentgroup="groupA")); and
(studentList=
StudentGroup.objects.filter(name="groupA")). The form in rendered in the
template. 

My main propose is to do that using newforms. Anybody can help?

Thanks a lot and Happy Christmas.
-- 
View this message in context: 
http://www.nabble.com/newforms-and-many-objects-instances-tp14479408p14479408.html
Sent from the django-users mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~--~~~~--~~--~--~---