Opened 7 years ago

Closed 7 years ago

#9392 closed (duplicate)

Inherited model fields being duplicated in Forms

Reported by: terpsquared Owned by: nobody
Component: Uncategorized Version: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


Possibly related to #9371.

Given an inherited model of the form:

from django.db import models
from django.contrib.auth.models import User, UserManager
from django.utils.translation import ugettext_lazy as _
from datetime import datetime

class Customuser(User):
    username = models.CharField(_('customer id'), max_length=30, unique=True, help_text=_("Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores)."))
    email_id = models.EmailField(_('e-mail address'), blank=True, null=True, unique=True, db_index=True)

    def __unicode__(self):
        return u'%s' % self.username

    # Use UserManager to get the create_user method, etc.
    objects = UserManager()

A form specifying the inherited field "email_id" will display the email_id field twice during output. For example,

from django import forms
from django.forms import ModelForm

class CustomForm1(ModelForm):
    class Meta:
        model = Customuser
        fields = ('email_id')

will result in the following html output from the form:

<tr><th><label for="id_0-email">E-mail address:</label></th><td><input id="id_0-email" type="text" name="0-email" maxlength="75" /></td></tr>
<tr><th><label for="id_0-email_id">E-mail address:</label></th><td><input id="id_0-email_id" type="text" name="0-email_id" maxlength="75" /></td></tr>

Something seems to confusing the email and email_id fields, causing them both to show even though only the email_id field is specified.

Change History (2)

comment:1 Changed 7 years ago by terpsquared

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

I thought that the problem might have been related to the _id suffix on the email_id field, but I got the same behavior with the fieldname "user_email" instead of "email_id".

comment:2 Changed 7 years ago by mtredinnick

  • Resolution set to duplicate
  • Status changed from new to closed

Looks like a dupe of #9393.

Note: See TracTickets for help on using tickets.
Back to Top