I'm trying to subclass django.newforms.forms.Form with class
ExtendedForm:
from django import newforms as forms
from django.db import models
class ExtendedForm(forms.Form):
base_fields = { 'new_field': forms.CharField() }
Then, given some class:
class MyModel(models.Model):
first_field = models.CharField(maxlength=16)
second_field = models.CharField(maxlength=16)
I call the following:
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
DeclarativeFieldsMeta class is expecting the fields as class attributes,
when instead, the fields are in the attrs['base_fields']. If I apply
the attached diff, then it seems to work. Is this a valid fix, or am I
missing something?
Regards,
Casey
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: django/newforms/forms.py
===================================================================
--- django/newforms/forms.py (revision 5148)
+++ django/newforms/forms.py (working copy)
@@ -37,8 +37,11 @@
'base_fields', taking into account parent class 'base_fields' as well.
"""
def __new__(cls, name, bases, attrs):
- fields = [(field_name, attrs.pop(field_name)) for field_name, obj in attrs.items() if isinstance(obj, Field)]
- fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
+ if attrs.has_key('base_fields'):
+ fields = attrs['base_fields'].items()
+ fields.sort(lambda x, y: cmp(x[1].creation_counter, y[1].creation_counter))
+ else:
+ fields = []
# If this class is subclassing another Form, add that Form's fields.
# Note that we loop over the bases in *reverse*. This is necessary in