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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T15:28:34+00:00 2026-05-22T15:28:34+00:00

I have an InteferField set in models called the status. I have a method

  • 0

I have an InteferField set in models called the status. I have a method that is two switch the value of two rows statuses.

Row one -> status = 1
Row two -> status = 2

Now, I figure, if I switch row one’s status to some unattainable reach (99) I could use that as the middle man to switch row two and then switch row one.

Get status = 1 -> Row one
Get status = 2 -> Row two
Set Row one -> status = 99
Save Row one
Set Row two -> status = 1
Save Row two
Get status = 99 -> Row one
Set Row one -> status = 2
Save Row one

The strange thing is, the data reverts. If I just change the status of Row one to 99, it will change to 99 and then a moment later, back to its original value. We’re not sure why this is happening, but it turns out nothing is come from this at all.

original = 1
swap = 2

originalCase = Case.objects.get(queue_num = original)
#swapCase = Case.objects.get(queue_num = swap)
originalCase.queue_num = 99
originalCase.save()
#swapCase.queue_num = original
#swapCase.save()
#originalCase = Case.objects.get(queue_num = 99)
#originalCase.queue_num = swap
#originalCase.save()
return HttpResponse(Case.objects.filter(queue_num__gt=0).order_by('queue_num'))

Is it because we’re querying to fast and it’s not updating in time for the next update? Or is there a flaw in my logic?

  • 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-22T15:28:35+00:00Added an answer on May 22, 2026 at 3:28 pm

    Hmmm… Shouldn’t the following:

    originalCase = Case.objects.get(queue_num = swap)
    

    Be this:

    originalCase = Case.objects.get(queue_num = 99)
    

    If you copy and pasted that code as is, that’s your problem. You’re essentially fetching the one you just changed and changing it back.

    UPDATE:

    Simplifying your code may help ferret out the problem, as well. You don’t technically need a swap placeholder. Since the query hits the database only once when initially fetching all the objects, you could do something like the following:

    cases = Case.objects.all()
    for case in cases:
        if case.queue_num == original:
            case.queue_num = swap
        elif case.queue_num == swap:
            case.queue_num = original
    
        case.save()
    

    Or if you want to keep the same idea, you could even do the following (which might actually be simpler):

    Case.objects.filter(queue_num=original).update(queue_num=99)
    Case.objects.filter(queue_num=swap).update(queue_num=original)
    Case.objects.filter(queue_num=99).update(queue_num=swap)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script that appends some rows to a table. One of the
I have a legacy database that I've set up some models to use. The
I have a models in Django that are something like this: class Classification(models.Model): name
I have the following two models class Author(Model): name = CharField() class Publication(Model): title
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
If I have some grouped choices for a models.IntegerField, how can I set the
I have a model that looks like this class RSVP (models.Model): def __unicode__(self): return
I have a following model: class Car(models.Model): make = models.CharField(max_length=40) mileage_limit = models.IntegerField() mileage
Hay, i have a simple model class Manufacturer(models.Model): name = models.CharField() car_count = models.IntegerField()
Lets say I have model inheritance set up in the way defined below. 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.