Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expected type 'str', got 'CharField' instead

In my Django project in PyCharm, I have enabled type hinting. In a Django model, I have defined a CharField. In a method in the model, I want to use that as an argument in a function that expects a string. I get the following warning however:

Expected type 'str', got 'CharField' instead

I realize that the two types are not the same. What would be the best way to not get the field itself, but the contents of the field as argument to that function. Note that behaviorly, everything is correct already, the receiving function already treats the argument as a string.

like image 894
physicalattraction Avatar asked Oct 17 '25 15:10

physicalattraction


1 Answers

I found out that this issue was resolved after I had enabled Django support in my project in PyCharm.

PyCharm screenshot of settings where to Enable Django Support

like image 132
physicalattraction Avatar answered Oct 21 '25 11:10

physicalattraction



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!