0

I am trying to render 2 classes in forms and display it in another template, i have no idea on what to do and help would be appreciated so much

here is my code in forms.py

class sample_tableform(ModelForm):

name = forms.CharField( max_length=50, label = ("name"),  help_text = ("Name:"),
    error_messages = {'invalid':"Your name may only contain letters.", 'required':"Enter your name.", 'unique':'Name already exists'}, validators=[RegexValidator( regex='^[a-zA-Z ]*$', message=("Forgotten message."),)])
email = forms.CharField( max_length=50, label = ("email"), help_text = ("Email:"),
    error_messages = {'invalid':"Enter a valid email.", 'required':"Enter your email.", 'unique':'email already exists'}, validators=[RegexValidator( regex='^[\w.%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4} *$', message=("Forgotten message."),)])
pnum = forms.CharField( max_length=11, min_length=11, label = ("pnum"), help_text = ("Phone Number:"),
    error_messages = {'invalid':"Enter a valid phone number.", 'required':"Enter your phone number.", 'min_length':"Should contain 11 digits"}, validators=[RegexValidator( regex='^[0-9]*$', message=("Forgotten message."),)])
class Meta:
    model = sample_table
    fields = ('name', 'email', 'pnum',)

class confirm(ModelForm):

pnum = forms.CharField( max_length=11, min_length=11, label = ("pnum"), help_text = ("Phone Number:"),

class Meta:
    model = sample_table
    fields = ('confirm',)`

thank you in advance :*

Juan Carlos Asuncion
  • 927
  • 2
  • 10
  • 26
  • possible duplicate of [Django: Can class-based views accept two forms at a time?](http://stackoverflow.com/questions/15497693/django-can-class-based-views-accept-two-forms-at-a-time) – Louis Sep 02 '15 at 16:37

1 Answers1

0

Inside your view, you can pass two forms objects via your context. I suppose you could do something like this:

context = Context({'form_1': Form_1, 'form_2': Form_2})

Have a look to a similar previous answer on stackoverflow here: https://stackoverflow.com/a/15499249/3967218 :)

Community
  • 1
  • 1
AL3X
  • 61
  • 4
  • 1
    I actually solved it, i'm just a beginner so i don't understand how the templates render it's fields and it turns out it came from view and not in forms i just defined another function and set it to my second class the call it in my second templates thanks for the reply – Juan Carlos Asuncion Sep 02 '15 at 14:19
  • De nada Juan Carlos :) – AL3X Sep 03 '15 at 09:56