Writing custom model fields: The __metaclass__ attribute is no longer supported in Python 3
As Django 1.5 introduces the support of Python 3, I think the documentation of "Writing custom model fields" should warn developers that:
class MyCustomField(models.Field):
__metaclass__ = models.SubfieldBase
is no longer supported and that they should use:
class MyCustomField(models.Field, metaclass=models.SubfieldBase):
...
instead.
Writing in the first (old) fashion results in no errors or warnings whatsoever. The to_python() method is just not called as it should be...
Change History
(9)
Triage Stage: |
Unreviewed → Design decision needed
|
Type: |
Uncategorized → New feature
|
Triage Stage: |
Design decision needed → Accepted
|
Triage Stage: |
Accepted → Ready for checkin
|
Type: |
New feature → Cleanup/optimization
|
Resolution: |
→ fixed
|
Status: |
new → closed
|
The second version isn't acceptable as is because it's a syntax error under Python 2. If you want a single snippet that works in Python 2 and 3 you have to use
six.with_metaclass
.Currently the documentation assumes Python 2. We haven't chosen how to document things that are different in Python 2 and 3 yet.
Technically, this ticket is valid, but it covers about 0.1% of the problem. For starters, the docs has tons of
__unicode__
methods that don't make any sense under Python 3...