List Info

Thread: newforms and many objects instances




newforms and many objects instances
country flaguser name
United States
2007-12-23 12:34:54

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-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: newforms and many objects instances
user name
2007-12-24 14:07:09
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 <desdecha...gmail.com> 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-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 )