Additional fields not registered when subclassing Forms imported from other applications?

2 views
Skip to first unread message

Simon Meers

unread,
Feb 9, 2010, 7:21:07 PM2/9/10
to django...@googlegroups.com
This may be a python quirk I'm unaware of, or perhaps a Django bug, I'm not sure:

#------------------------------------------------------------
# forms.py:
#------------------------------------------------------------
    from django import forms
    class TestForm(forms.Form):
        test_field = forms.BooleanField()
#------------------------------------------------------------

#------------------------------------------------------------
# test.py:
#------------------------------------------------------------
    # import the same class from two different locations:
    from project_name.forms import TestForm
    from project_name.some_module.forms import TestForm as TestForm2
   
    class MyForm(TestForm):
        extra_field = forms.BooleanField()
   
    print MyForm().fields.keys()
    # prints: ['test_field', 'extra_field'] as expected
   
    class MyForm2(TestForm2):
        extra_field = forms.BooleanField()
   
    print MyForm2().fields.keys()
    # prints: ['test_field']
    # extra fields not registered if superclass imported from other app/module!
#------------------------------------------------------------

Python 2.6.4, Django SVN-12401

What is going on here?

Simon
Reply all
Reply to author
Forward
0 new messages