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

  • SEARCH
  • Home
  • 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 7880347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:07:27+00:00 2026-06-03T04:07:27+00:00

For 2 days i have been stucked at transaction problem in my Django project.

  • 0

For 2 days i have been stucked at transaction problem in my Django project. I’m developing a messenger system and when i send a message to some user, the sent message appears correctly in outbox div (with jQuery/Ajax, not refresh page). Well, If i send another message, the new message which appears in outbox now is the same as previous sent.

All messages i send are like the first. In database table the messages are well saved, so i guess problem comes from query.

The query is next:

@login_required(login_url='/')
def getmessage(request, mode=None):
if request.is_ajax():
    if request.method == "GET":
        # Retrieve last message sent by user
        Message.objects.update()
        q = Message.objects.filter(sender=request.user).order_by('send_at')[:1]

        response = {}
        for sent in q:
            sent_message = {}
            sent_message['recipient'] = sent.recipient.username
            print sent.recipient.username
            sent_message['body'] = sent.body
            response.update({'sent': sent_message})

        # Make json object
        json = simplejson.dumps(response)

        # Send answer to client side
        return HttpResponse(json, mimetype='application/json')
    else:
        # No POST request, redirecting
        return HttpResponseRedirect('/messenger/')
else:
    # No AJAX request, redirecting
    return HttpResponseRedirect('/messenger/')

let’s pay attention to line “print sent.recipient.username”. This line always print the first message recipient name.

I have been reading some threads around stackoverflow talking about this problem, but handling manually the transactions i haven’t got any success. Even making “Message.objects.update()” before the query it doesn’t work.

Any suggestion? It’s very annoying to not understand how does it happening.

If you need more information like model code or whatever, tell it to me.

Thanks!

  • 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-06-03T04:07:29+00:00Added an answer on June 3, 2026 at 4:07 am

    You query is ordering the results by “send_at”, which presumably gives you the first message sent. If you want the last, you’ll need to order on “-send_at”, eg.

    q = Message.objects.filter(sender=request.user).order_by('-send_at')[:1]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good morning. I've been having this issue for some days and have been lokking
For some days now I have been suffering with UITabBarItem s. I have done
I have been working on a project for a few days now and have
for some days now I have been trying to make a simple mod_rewrite rule
During last three days I have been trying to solve Project Euler 15 in
for some days i have been struggeling with making only certain ips accessing my
For some of you it might sound trvial, but for days I have been
Hi For many days I have been working on this problem in MySQL, however
Over the past few days I have been trying to create/run a project in
For the last few days I have been attempting to find a method to

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.