physicalattraction
physicalattraction

Reputation: 6858

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.

Upvotes: 4

Views: 1427

Answers (1)

physicalattraction
physicalattraction

Reputation: 6858

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

Upvotes: 4

Related Questions