0

I'm new to Django, creating a website which has multiple forms(mostly check boxes) that need to be filled to submit a task. Models.py

class M1(models.Model):
  T1=model.NullBooleanField()
  T2= model.NullBooleanField()
class M2(models.Model):
  N1=model.NullBooleanField()
  N2= model.NullBooleanField()

Forms.py`

class M1Form((forms.ModelForm): 
  class Meta: 
     model = M1 
     fields = ['T1','T2']
     widgets=.........
 class M2Form((forms.ModelForm): 
   class Meta: 
     model = M2 
     fields = ['N1','N2']
     widgets=.........

views.py

   def home_page(request):
       tmpl_vars = { 
       'form': M1Form        
    }    
    return render(request, 'my_app/test.html',tmpl_vars)

My question is I'm not clear on how to load the forms of M2Form through the views.py. Right now m trying to access it on the webpage and currently only the M1Form variables are visible.

1
  • 1
    I'm not sure why you think this is complicated. You're passing M1Form to the template vars, why can't you also pass M2Form? Commented Dec 1, 2015 at 10:24

1 Answer 1

1

If you need detailed explanation, comment of Daniel Reseman means to write in views.py

def home_page(request):
   tmpl_vars = { 
       'form': M1Form,
       'form2': M2Form,
   }    
   return render(request, 'my_app/test.html',tmpl_vars)

Then in template you can use it as {{form2}}

Sign up to request clarification or add additional context in comments.

2 Comments

if Invalid syntax, I need to see how do you wirte in views.py exactly (write in bottom of question), or it solved?
its solved added () -> 'form': M1Form(), 'form2': M2Form (),

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.