title: Cannot filter a query once slice has been taken django
body: <p>Follow up onto:</p>
  <p><a href="https://stackoverflow.com/questions/64954687/autofield-should-be-present-but-its-not-django/64954724#64954724">AutoField should be present but it&#39;s not (django)?</a></p>
  <p>related to:</p>
  <p><a href="https://stackoverflow.com/questions/35206482/cannot-update-a-query-once-a-slice-has-been-taken-best-practices">&quot;Cannot update a query once a slice has been taken&quot;. Best practices?</a></p>
  <p>I don't need to filter objects, only order by date and select the most recent one:</p>
  <pre><code>def get_latest_currency(self):
      &quot;&quot;&quot;
      Return most up to date value
      &quot;&quot;&quot;
      up_to_date_currency = Currency.objects.order_by('-currency_value_in_dollars_date')[:1]
  
      if not up_to_date_currency.exists():
          # No objects yet; fetch currencies
          update_coins_table()
  
      return Currency.objects.order_by('-currency_value_in_dollars_date')[:1]
  </code></pre>
  <p><strong>up_to_date_currency</strong>  is initialized correctly; the last line gives:</p>
  <pre><code>    assert not self.query.is_sliced, \
  AssertionError: Cannot filter a query once a slice has been taken.
  </code></pre>
  <p>This code represents a view (I want to return a plain JSON object (this is a REST endpoint)). Why is django complaining about a filter when only a slice was used?</p>
  <p>get_latest_currency is the name of the endpoint:</p>
  <pre><code>import sys
  
  from django.urls import path
  from . import views
  
  app_name = 'manage_crypto_currency'
  urlpatterns = [
      path('get_currency/', views.get_latest_currency, name='index'),
  ]
  </code></pre>
  <p>Stacktrace:</p>
  <pre><code>Internal Server Error: /get_currency/
  Traceback (most recent call last):
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\core\handlers\exception.py&quot;, line 47, in inner
      response = get_response(request)
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\utils\deprecation.py&quot;, line 116, in __call__
      response = self.process_response(request, response)
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\middleware\clickjacking.py&quot;, line 26, in process_response
      if response.get('X-Frame-Options') is not None:
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\db\models\query.py&quot;, line 418, in get
      clone = self._chain() if self.query.combinator else self.filter(*args, **kwargs)
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\db\models\query.py&quot;, line 942, in filter
      return self._filter_or_exclude(False, *args, **kwargs)
    File &quot;C:\projects\crypto-currency-board\venv\lib\site-packages\django\db\models\query.py&quot;, line 954, in _filter_or_exclude
      assert not self.query.is_sliced, \
  AssertionError: Cannot filter a query once a slice has been taken.
  </code></pre>
  <p>Tried wrapping the objects around HttpReponse():</p>
  <p>return HttpResponse(Currency.objects.order_by('-currency_value_in_dollars_date')[:1], content_type='application'
  '/json')</p>
  <p>This works but only the name is, for some reason, returned.</p>