You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@admin.register(MyModel)classMyModelAdmin(BaseAdminMixin):
…
defformfield_for_manytomany(
self, db_field: "ManyToManyField", request: "Optional[HttpRequest]", **kwargs
) ->"ModelMultipleChoiceField":
"""Manually use filter_horizontal for input_recipes. This is required due to Django not using a non-auto through model. Ref: https://code.djangoproject.com/ticket/12203#comment:22 """ifdb_field.name=="m2m_with_through":
assertnotdb_field.remote_field.through._meta.auto_createddb=kwargs.get("using")
kwargs["widget"] =widgets.FilteredSelectMultiple(
db_field.verbose_name,
False, # filter_horizontal
)
queryset=self.get_field_queryset(db, db_field, request)
ifquerysetisnotNone:
kwargs["queryset"] =querysetform_field=db_field.formfield(**kwargs)
ifTYPE_CHECKING:
# assert type as it is not provided via django-stubs yet.assertisinstance(form_field, ModelMultipleChoiceField)
msg=_(
"Hold down “Control”, or “Command” on a Mac, to select more than one."
)
help_text=form_field.help_textform_field.help_text= (
format_lazy("{} {}", help_text, msg) ifhelp_textelsemsg
)
returnform_fieldreturnsuper().formfield_for_manytomany(db_field, request, **kwargs)
The problem still exists, if you try to declare a proxy model using the through model, it throws the warning: Name "Audio.panel.through" is not defined
e.g.
class AudioPanel(Audio.panel.through):
class Meta:
proxy = True
I am overriding
BaseModelAdmin.formfield_for_manytomany
(code) and noticed two issues:assert not db_field.remote_field.through._meta.auto_created
fails with:"Field[Any, Any]" has no attribute "through" [attr-defined]
(code ref)formfield
is typed asAny
, which can be fixed with an assert/type-override (django-stubs/django-stubs/db/models/fields/__init__.pyi
Lines 180 to 181 in 593d04d
System information
python
version: 3.9.9django
version: 3.2.9mypy
version: 0.910django-stubs
version: 1.9.0 / master (593d04d)django-stubs-ext
version: -The text was updated successfully, but these errors were encountered: