Jupyter and some interactive shells run user code inside an already-running event loop. Django sees that and refuses ORM access with SynchronousOnlyOperation, even though the notebook is single-threaded and the query would be perfectly safe.
Setting the environment variable DJANGO_ALLOW_ASYNC_UNSAFE to any non-empty value before Django is imported turns the check off. In a notebook the reliable order is to set os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "1" and DJANGO_SETTINGS_MODULE, then call django.setup(), in that sequence and in the first cell.
Do not set it in a web server process. The check exists because the ORM will otherwise block the event loop and, worse, share a connection across concurrent tasks in ways that corrupt transaction state. The django-extensions package's shell_plus --notebook sets it for you, which is why the variable often appears in a project without anyone remembering adding it. Treat its presence in a production environment file as a bug worth tracing.