Or the either way round      instead of form = CompanyForm(request.POST),
make it PersonForm(request.POST).

On Fri, 8 Nov 2019, 4:26 pm Paras Jain, <[email protected]> wrote:

> Hy, i am not getting my all fields on the my page which is written inside
> the forms.py of 'PersonForm'
>
>
> models.py:
> from django.db import models
>
> # Create your models here.
> TITLE_CHOICES = (
>     ('Normal', 'Manager'),
> )
>
> class Company(models.Model):
>     email = models.EmailField()
>
>     def __str__(self):                                #will return search
> add by the user
>         return '{}'.format(self.email)
>
>
>     class Meta:
>         verbose_name_plural = 'Company'
>
>
>
> class Person(models.Model):
>     name = models.CharField(max_length=255)
>     email = models.EmailField()
>     type = models.CharField(max_length=6, choices=TITLE_CHOICES)
>
>     class Meta:
>         verbose_name_plural = 'Person'
>
>
> forms.py:
> from django import forms
> from .models import Company,Person
>
> class CompanyForm(forms.ModelForm):
>     class Meta:
>         model = Company
>         fields = ('email',)
>
> class PersonForm(forms.ModelForm):
>     class Meta:
>         model = Person
>         fields = ('type', 'name','email',)
>
> views.py:
> from django.shortcuts import render
> from .forms import CompanyForm, PersonForm
> from django.views.generic  import CreateView
>
> # Create your views here.
> def home(request):
>
>     form = CompanyForm()
>
>     if request.method  == "POST":
>         form = CompanyForm(request.POST)
>
>         if form.is_valid():
>             form.save(commit=True)
>
>         else:
>             print('Error form invalid')
>
>     return render(request, 'home.html', {'form':form})
>
> def add(request):
>
>     form= PersonForm()
>     if request.method  == "POST":
>         form = CompanyForm(request.POST)
>
>         if form.is_valid():
>             form.save(commit=True)
>
>
>
>     return render(request, 'add.html', {'form':form})
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/CAMtmBS-LUNiBy-ey%2BrpvB1%3DRPo6n9x3GwuSnOswObBRt2OZK1g%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-users/CAMtmBS-LUNiBy-ey%2BrpvB1%3DRPo6n9x3GwuSnOswObBRt2OZK1g%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/CAFFcXKLqN1ZUS3ognDyOwRB0drZ6QG667GBYUzCq_W2Xb_Q9xA%40mail.gmail.com.

Reply via email to