0

I have a model with 5 entities and intend to create a form (on the same page) but do not know how to integrate more than one form.

In my main, i can play very well with the forms and write to database, but I need to put more fields on the page. These fields are of different models. ** My models: Teacher, Account(ReferenceProperty), Experience (ReferenceProperty), ServiceDistribution(ReferenceProperty), Experience(ReferenceProperty)

My forms:

  class TeacherForm(djangoforms.ModelForm):
    class Meta:
        model =models.Teacher
        exclude = ['user']

and the same for other models

My Main:

class CreateCvHandler(webapp.RequestHandler):
    def post(self):
        if self.request.get('EscTeacher'):
            id = int(self.request.get('EscTeacher'))
            teacher=models.teacher.get(db.Key.from_path('Teacher', id))
        else:
            teacher= models.teacher()

        data = forms.TeacherForm(data = self.request.POST)
        if data.is_valid():

            userList= models.Account.all()
            userList.filter('user =', users.get_current_user())

            for user in userList:
                teacher.user=user.key()
            teacher.unity=self.request.get('unity')
            teacher.category=self.request.get('category')
            teacher.regime=self.request.get('regime')


            teacher.put()
            self.redirect('/academy')
        else:
            self.redirect('/createCv')**

Help Please...

Nick Johnson
  • 100,655
  • 16
  • 128
  • 198
Martinho
  • 379
  • 1
  • 3
  • 14
  • I apologize if I was not specific. My program will help teachers meet their curriculum vitae. The sheet will be printed in pdf format. This single sheet has several forms that are of different classes. So far only seen examples of forms with only one class and I'm having trouble getting the form with more than one class, write on DB and display the data. In my particular case, the sheet with the forms would have five classes. – Martinho Aug 16 '10 at 11:45

1 Answers1

1

If I understood you correctly what you can do is create forms for each model and display them in the template having a single save button. Now when submitted, in your view you can validate each form and add or update the db as required.

Here is a link to an answer to a question similar to what you have asked.. Django: multiple models in one template using forms

Community
  • 1
  • 1
Shwetanka
  • 4,976
  • 11
  • 44
  • 68