typeddjango / django-stubs

PEP-484 stubs for Django
MIT License
1.61k stars 451 forks source link

Type inference on `ManyToManyField` on `ModelForm` #1245

Open adnathanail opened 2 years ago

adnathanail commented 2 years ago

Bug report

What's wrong

I have a model with a many to many field, and a model form pointing to that model.

In the __init__ on that model I want to override the queryset for the many to many field, but I get error: "Field" has no attribute "queryset"

I think this is because .queryset only exists on ModelChoiceField

Is there anyway I can type hint this correctly? Or does anyone have a suggestion for a PR that I could try to write?

I have made a minimal reproduction, it is the only failing test in this fork:

https://github.com/adnathanail/django-stubs/actions/runs/3430356832/jobs/5717214486

How is that should be

The tests on that repo should pass

System information

adnathanail commented 2 years ago

I think this issue could be related #1054