I have a models like
class MyModel(models.Model):
name = models.CharField()
updated_on = models.DateTimeField()
Now I am querying this like
m = MyModel.objets.get(id=2)
Here I want to check if the field is of certain type I want to do some stuff like
from django.db.models import DateTimeField
if isinstance(m.updated_on, DateTimeField):
// do something
But here I am getting false. Is there any workaround by which I can achieve this ??
To get the type of field:
Model._meta.get_field("fieldname")
You can use this:
from django.db.models import DateTimeField
if isinstance(MyModel._meta.get_field('updated_on'),DateTimeField):
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With