title: How to get data from django orm inside an asynchronous function?
body: <p>I need to retrieve data from the database inside an asynchronous function. If I retrieve only one object by executing e.g:</p>
  <pre><code>users = await sync_to_async(Creators.objects.first)()
  </code></pre>
  <p>everything works as it should. But if the response contains multiple objects, I get an error.</p>
  <pre><code>@sync_to_async
  def get_creators():
      return Creators.objects.all()
  
  async def CreateBotAll():
      users = await get_creators()
  
      for user in users:
          print(user)
  </code></pre>
  <p>Tracing:</p>
  <pre><code>Traceback (most recent call last):
  File &quot;/home/django/django_venv/lib/python3.8/site- 
  packages/django/core/handlers/exception.py&quot;, line 47, in inner
  response = get_response(request)
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/core/handlers/base.py&quot;, line 
  181, in _get_response
  response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File &quot;/home/django/django_venv/src/reseller/views.py&quot;, line 29, in test
  asyncio.run(TgAssistant.CreateBotAll())
  File &quot;/usr/lib/python3.8/asyncio/runners.py&quot;, line 44, in run
  return loop.run_until_complete(main)
  File &quot;/usr/lib/python3.8/asyncio/base_events.py&quot;, line 616, in run_until_complete
  return future.result()
  File &quot;/home/django/django_venv/src/reseller/TgAssistant.py&quot;, line 84, in CreateBotAll
  for user in users:
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/db/models/query.py&quot;, line 
  280, in __iter__
  self._fetch_all()
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/db/models/query.py&quot;, line 
  1324, in _fetch_all
  self._result_cache = list(self._iterable_class(self))
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/db/models/query.py&quot;, line 
  51, in __iter__
  results = compiler.execute_sql(chunked_fetch=self.chunked_fetch, chunk_size=self.chunk_size)
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/db/models/sql/compiler.py&quot;, 
  line 1173, in execute_sql
  cursor = self.connection.cursor()
  File &quot;/home/django/django_venv/lib/python3.8/site-packages/django/utils/asyncio.py&quot;, line 31, 
  in inner
  raise SynchronousOnlyOperation(message)
  django.core.exceptions.SynchronousOnlyOperation: You cannot call this from an async context - 
  use a thread or sync_to_async.
  </code></pre>
  <p>I made it work that way:</p>
  <pre><code>@sync_to_async
  def get_creators():
      sql = Creators.objects.all()
      x = [creator for creator in sql]
      return x
  </code></pre>
  <p>Isn't there a more elegant solution?</p>