Get Python type of Django's model field? -
how can corresponding python type of django model's field class ?
from django.db import models class mymodel(models.model): value = models.decimalfield() type(mymodel._meta.get_field('value')) # <class 'django.db.models.fields.decimalfield'>
i'm looking how can corresponding python type field's value - decimal.decimal
in case.
any idea ?
p.s. i've attempted work around field's default
attribute, won't work in cases field has no default value defined.
i don't think can decide actual python type programmatically there. part of due python's dynamic type. if @ doc converting values python objects, there no hard predefined type field: can write custom field returns object in different types depending on database value. doc of model fields specifies python type corresponds each field type, can "statically".
but why need know python types in advance in order serialize them? serialize modules supposed you, throw them objects need serialize. python dynamically typed language.
Comments
Post a Comment