On upgrade to Django 1.9, I now get the warning
RemovedInDjango110Warning: SubfieldBase has been deprecated. Use Field.from_db_value instead.
I see where the problem arises. I have some custom field definitions, and in them I have __metaclass__ = models.SubfieldBase
. For example,
class DurationField(models.FloatField):
__metaclass__ = models.SubfieldBase
def __init__(self, *args, **kwargs):
...
If the __metaclass__
statement is deprecated, what am I supposed to replace it with exactly?
Do I just take it out and add a from_db_value
method like in the example here: https://docs.djangoproject.com/en/1.9/howto/custom-model-fields/#converting-values-to-python-objects
?
And how are from_db_value
and to_python
different? The both seem to convert database data to Python objects?