django-types icon indicating copy to clipboard operation
django-types copied to clipboard

ManyToManyField[Unknown, Unknown]

Open collinanderson opened this issue 2 years ago • 2 comments

VSCode is saying my models.ManyToManyField(MyModel, blank=True) is ManyToManyField[Unknown, Unknown]. I'm wondering if that's because I don't have a through model specified? Is there any way to make this work correctly without hand-generating a through model? My ForeignKeys are working fine.

collinanderson avatar May 04 '22 18:05 collinanderson

Hmm we might need to tweak the overloads a bit, I think it should be possible to have it typed properly without having to specify the through model

sbdchd avatar May 05 '22 12:05 sbdchd

This is a workaround, a bit nasty because the mock line shadows the actual line, that, regarding my editor at least, is considered as unreachable:


    if TYPE_CHECKING:
        from django.db.models.manager import ManyToManyRelatedManager
        model1 = ManyToManyRelatedManager[Model1, 'Model2']()
    else:
        model1 = models.ManyToManyField(Model1, blank=True)

Javrd avatar Mar 14 '23 11:03 Javrd