Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 289771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:56:14+00:00 2026-05-12T05:56:14+00:00

I have a simple django’s query set like: qs = AModel.objects.exclude(state=F).order_by(order) I’d like to

  • 0

I have a simple django’s query set like:

qs = AModel.objects.exclude(state="F").order_by("order")

I’d like to use it as follows:

qs[0:3].update(state='F')
expected = qs[3] # throws error here

But last statement throws:
“Cannot update a query once a slice has been taken.”

How can I duplicate the query set?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:56:14+00:00Added an answer on May 12, 2026 at 5:56 am

    It’s the first line throwing the error: you can’t do qs[0:3].update(). qs[0:3] is taking a slice; update() is updating the query.

    update() is meant for bulk updates, resulting in SQL queries like

    UPDATE app_model SET state = 'F' WHERE state <> 'F';
    

    You’re trying to update the first three items according to “order”, but that can’t be done with this type of UPDATE–you can’t order or limit an SQL UPDATE. It needs to be written differently, eg.

    UPDATE app_model SET state = 'F' WHERE id IN (
        SELECT id FROM app_model WHERE state <> 'F' ORDER BY order LIMIT 3
    ) AS sub;
    

    but Django can’t do that for you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple view in Django: @render_to('episode_list.html') def list_episodes(request, season): query = Episode.objects.filter(season=season)
I have a simple django page that has a counter on it. I use
I have set up a few models in a simple django project. When I
...Like Django's session or cookies Does anyone have a simple way of allowing this?
I'm new to django. I have 2 simple objects, lets call them - File
I have a simple set of urls in a Django url conf file which
I have two simple models in my Django app. Here's what they look like:
I have some simple Django Models like this: class Event(models.Model): # some stuff class
I have two simple tables in Django which looks like: class Session(models.Model): id =
I have a simple Django model like: class Person(models.Model): referrer = models.ForeignKey('self', null=True) ...

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.