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 5845945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T12:30:26+00:00 2026-05-22T12:30:26+00:00

My database is set up with a list of cases with an ID from

  • 0

My database is set up with a list of cases with an ID from our ticketing system, a location, an assigned person and a short description taken from the ticket:

  • Case
    • ID
    • Location
    • Assigned Person
    • Short Description
    • Status

Now to help better sort things, depending on certain status values, we change the QuerySet after querying it.

current_active = Case.objects.filter(queue_num=0,status__lt=6)
for item in current_active:
    if(item.location == 'NPH'):
        item.assigned_tech = 'NPH'
    elif(item.location == 'Bins'):
        item.assigned_tech = 'Bins'
    elif(item.status > '2' and item.status < '6'):
        item.assigned_tech = 'Pending'

I was wondering if there was any way to sort this new modified QuerySet. We know it prints correctly, it just comes down to the sorting that gets messed up.

UPDATE 2

current_active = Case.objects.filter(queue_num=0,status__lt=6)
current_active_list = []
for item in current_active:
    number = item.id
    item.id = '%07d' % number
    phone = item.myneuname.phonenumber
    if(len(phone) > 7):
        formattedPhone = phone[:-10]+' ('+phone[-10:-7]+') '+phone[-7:-4]+'-'+phone[-4:]
        item.myneuname.phonenumber = formattedPhone
    if(item.location == 'NPH'):
        item.assigned_tech = 'NPH'
    elif(item.location == 'Bins'):
        item.assigned_tech = 'Bins'
    elif(item.status > '2' and item.status < '6'):
        item.assigned_tech = 'Pending'
    current_active_list.append(item)
current_active_list.sort(key=lambda x: x.assigned_tech)

While this is not idea and Django-style, this does work. If you have the same issue and find a more reasonable way to fix this problem, please don’t hesitate to reply. Making a Python list seemed the only way possible without saving data.

  • 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-22T12:30:26+00:00Added an answer on May 22, 2026 at 12:30 pm

    Since you’re evaluating the queryset and then modifying some of the elements without saving, you need to avoid anything that goes back to the database and re-evaluates it. In your case, there’s nothing wrong with simply ordering the list in Python – for example:

    current_active.sort(key=lambda x: x.assigned_tech)
    

    to sort by the assigned_tech field.

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

Sidebar

Related Questions

I have a checkbox list which is filled with entries from my database on
I am getting list of data from database from my Service Class Method mDataVO.getMarketData()
I'm using Hibernate to retrieve some data from a database. The result set returned
I have an SQL database set up in which I would like to use
I have a database set up with email and password, I'm trying to use
I have a legacy database set with NLS_LANG set to IW8ISO8859P8. This I cannot
I've got my database set up with three tables - code, tags, and code_tags
I have a MySQL database set-up in a hierarchy style. There are 4 tables
Suppose the following: I have a database set up on database.mywebsite.com , which resolves
Looking to have a database query set all the instance variables in a class:

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.