Opened 16 years ago
Closed 16 years ago
#9393 closed (duplicate)
Overridden inherited model fields being duplicated in forms
Reported by: | terpsquared | Owned by: | nobody |
---|---|---|---|
Component: | Uncategorized | Version: | dev |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Likely related to (but distinct from) #9392, and possibly #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 "username" will display the username field twice during output. For example,
from django import forms from django.forms import ModelForm class CustomForm1(ModelForm): class Meta: model = Customuser fields = ('username')
will result in the following html output from the form:
<tr><th><label for="id_0-username">Customer id:</label></th><td><input id="id_0-username" type="text" name="0-username" maxlength="30" /><br />Required. 30 characters or fewer. Alphanumeric characters only (letters, digits and underscores).</td></tr> <tr><th><label for="id_0-name">Name:</label></th><td><input id="id_0-name" type="text" name="0-name" maxlength="100" /></td></tr>
Notice that this is different from #9392. In that case, the email_id field is distinct from the email field, but both are being displayed. In this case, both the original field and the inherited field seem to be displayed.
A solution to this would necessitate a design decision: Only show the inherited field, provide a mechanism for specifying which field is intended, or throw an error would seem to be the best possible answers.
Change History (2)
comment:1 by , 16 years ago
comment:2 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
This is a bug, but not the one you're thinking of. It's a bug that duplicated model field names aren't explicitly flagged as errors in validation. There are far too many things that can go wrong when duplicating fields like this.
I'm going to close this as a duplicate of #8886, since that's describing another symptom of the same problem.
I may have failed to specify that the duplicated field here has the same name in the parent and child models.