I use community pycharm and the version of python is 3.6.1, django is 1.11.1. This warning has no affect on running, but I cannot use the IDE's auto complete.
6 Answers
132
votes
29
votes
11
votes
3
votes
2
votes
I found this hacky workaround using stub files:
models.py
from django.db import models
class Model(models.Model):
class Meta:
abstract = True
class SomeModel(Model):
pass
models.pyi
from django.db import models
class Model:
objects: models.Manager()
This should enable PyCharm's code completion:
This is similar to Campi's solution, but avoids the need to redeclare the default value
1
votes
Another solution i found is putting @python_2_unicode_compatible decorator on any model. It also requires you to have a str implementation four your function
For example:
# models.py
from django.utils.encoding import python_2_unicode_compatible
@python_2_unicode_compatible
class SomeModel(models.Model):
name = Models.CharField(max_length=255)
def __str__(self):
return self.name