Opened 8 years ago

Closed 8 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: master
Severity: Keywords:
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

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@… 8 years ago.

Download all attachments as: .zip

Change History (3)

Changed 8 years ago by ctdecci@…

comment:1 Changed 8 years ago by ctdecci@…

  • Component changed from Core framework to django.newforms
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

comment:2 Changed 8 years ago by SmileyChris

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

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

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