Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django 在一个页面上显示多个具有冲突字段名的表单_Django_Django Forms_Modelform - Fatal编程技术网

Django 在一个页面上显示多个具有冲突字段名的表单

Django 在一个页面上显示多个具有冲突字段名的表单,django,django-forms,modelform,Django,Django Forms,Modelform,我需要在同一页面上有两个表单,它们都有email字段,并且都是同时提交的: 具有电子邮件字段的人员表单: class PersonForm(forms.ModelForm): class Meta: model = Person fields = [ 'first_name', 'last_name', 'email' ] class OrganisationFor

我需要在同一页面上有两个表单,它们都有
email
字段,并且都是同时提交的:

具有
电子邮件
字段的人员表单:

class PersonForm(forms.ModelForm):
    class Meta:
        model = Person

        fields = [
            'first_name',
            'last_name',
            'email'
        ]
class OrganisationForm(forms.ModelForm):

    class Meta:
        model = Organisation

        fields = [
            'name',
            'url',
            'email',
        ]
以及组织形式,该组织形式还具有
电子邮件
字段:

class PersonForm(forms.ModelForm):
    class Meta:
        model = Person

        fields = [
            'first_name',
            'last_name',
            'email'
        ]
class OrganisationForm(forms.ModelForm):

    class Meta:
        model = Organisation

        fields = [
            'name',
            'url',
            'email',
        ]
但是,
request.POST.email
显然将始终具有最后显示的表单值,覆盖第一个值。有没有办法解决这个问题,比如我们将组织的
电子邮件
重命名为
组织的电子邮件

fields = [
    'name',
    'url',
    'email AS organisation_email',
]
无需在
组织表单中定义自定义字段:

org_email = models.EmailField(max_length=4096, blank=True, db_index=True)
并且必须覆盖
save()
方法?另外,我不喜欢重新定义
max_length
blank
属性,以防它们在原始
模型中发生更改