Opened 18 years ago
Closed 17 years ago
#4239 closed (duplicate)
child classes of Form only include base_fields attributes of parents
Reported by: | 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)
Change History (3)
by , 18 years ago
Attachment: | forms.diff added |
---|
comment:1 by , 17 years ago
Component: | Core framework → django.newforms |
---|
comment:2 by , 17 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
Closing as a dupe of #5050 which is a bit more comprehensive