Only import and patch contenttypes if it is listed in INSTALLED_APPS.

Applying the patch causes test failures if `django.contrib.contenttypes` is not in use on an application.