Get Python type of Django's model field?
Question: How can I get corresponding Python type of a 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 I get corresponding python type for field's value -
`decimal.Decimal` in this case.

Any idea ?

p.s. I've attempted to work around this with field's `default` attribute, but
it probably won't work in all cases where field has no default value defined.


Answer: I don't think you can decide the actual python type programmatically there.
Part of this is due to python's dynamic type. If you look at the doc for
[converting values to python
objects](https://docs.djangoproject.com/en/1.8/howto/custom-model-
fields/#converting-values-to-python-objects), there is no hard _predefined_
type for a field: you can write a custom field that returns object in
different types depending on the database value. The doc of [model
fields](https://docs.djangoproject.com/en/1.8/ref/models/fields/) specifies
what Python type corresponds to each field type, so you can do this
"statically".

But why would you need to know the Python types in advance in order to
serialize them? The serialize modules are supposed to do this for you, just
throw them the objects you need to serialize. Python is a dynamically typed
language.

