Unresolved attribute references for Django's ForeignKey field etc.


When I use PyCharm for my Django projects, I often suffer from PyCharm being unable to link attributes of a related model to corresponding ForeignKey (etc.) field. This results in lots of inspection warnings (underlines). Is there a way to make PyCharm recognize related model attributes?

from django.db import models

class ModelA(models.Model):
    some_field = models.BooleanField()

class ModelB(models.Model):
    model_a = models.ForeignKey(ModelA)

    def related_property(self):
        return self.model_a.some_field  # "some_field" is unresolved


Please sign in to leave a comment.