Fixed #23444 -- Prevented unnecessary ContentType object creation when using inlines

ContentType object is mistakenly created for `through` model of M2M relation when it is used in inline.
One last suggestion: Please add `stacklevel=2` to the `warnings.warn()` call.

https://docs.python.org/3/library/warnings.html#warnings.warn