Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Typing reverse relations #1641

Unanswered
Winspear asked this question in Q&A
Discussion options

Throughout my codebase I have a number of related_name relations defined. For most, django-stubs (latest release) seems to be generating the requisite annotations to make MyPy pass, but for certain models the annotation is not being generated. One example of this is a more complicated structure than a simple model to model, foreign key reference, as it uses an abstract base model, eg:

class BaseImage(models.Model):
 image = models.ImageField(blank=True)
class FruitImage(BaseImage):
 fruit = models.OneToOneField(
 Fruit,
 related_name="image")
class Fruit(models.Model):
 name = models.CharField(max_length=10)

With this particular structure, I am receiving the mypy error "Fruit" has no attribute "image"

Is there anything I need to do to properly annotate reverse relations of this form?

You must be logged in to vote

Replies: 1 comment

Comment options

Please, report this to our tracker: https://github.com/typeddjango/django-stubs

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /