Opened 18 years ago

Closed 17 years ago

#4239 closed (duplicate)

child classes of Form only include base_fields attributes of parents

Reported by: ctdecci@… Owned by: nobody
Component: Forms Version: dev
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Child classes of Form only include the base_fields attributes of their parent classes, not both, as it should. Here's an example:

from django import newforms as forms
from django.db import models

class ExtendedForm(forms.Form):
    base_fields = { 'new_field': forms.CharField() }

class MyModel(models.Model):
    first_field = models.CharField(maxlength=16)
    second_field = models.CharField(maxlength=16)

obj = MyModel.objects.get(id=1)
MyForm = form_for_instance(obj, form=ExtendedForm)
f = MyForm()

However, when I render f, only new_field shows up.

It appears that the most reasonable place to fix this at the moment is in the DeclarativeFieldsMeta.__new__ method. The method is expecting the fields as class attributes, when instead, the fields are in the attrs dict with the 'base_fields' index. I've attached a patch.

Attachments (1)

forms.diff (832 bytes ) - added by ctdecci@… 18 years ago.

Download all attachments as: .zip

Change History (3)

by ctdecci@…, 18 years ago

Attachment: forms.diff added

comment:1 by ctdecci@…, 18 years ago

Component: Core frameworkdjango.newforms

comment:2 by Chris Beaven, 17 years ago

Resolution: duplicate
Status: newclosed

Closing as a dupe of #5050 which is a bit more comprehensive

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