58π
β
If you were doing this:
model._meta.get_field('g').get_internal_type()
You could not possibly get that as a result.
Instead, you are doing this:
model._meta.get_field('g').get_internal_type
Which, as explained here, does not call the method, it just refers to the method as a bound method object. The return value is not part of that bound method object, itβs created by the method when the method is called. So, you have to call it. So you need the parentheses.
π€abarnert
12π
You can do this:
from django.db.models.fields import *
....
if model._meta.get_field('g').__class__ is UrlField:
....
....
or If you want to use String instead of working only with UrlField
....
if type(model._meta.get_field('g')) is eval('UrlField'):
....
....
or
isinstance(model._meta.get_field('g'), UrlField)
# This will return Boolean result
You Can also use equal β==β instead of βisβ
You can Check Offical Documentation for more information about
π€Pranav Raut
- [Django]-Actions triggered by field change in Django
- [Django]-Why second user login redirects me to /accounts/profile/ url in Django?
- [Django]-Django rest framework nested self-referential objects
- [Django]-Django: how does manytomanyfield with through appear in admin?
- [Django]-Django: FloatField or DecimalField for Currency?
- [Django]-Django β use reverse url mapping in settings
Source:stackexchange.com