[Django]-Convert raw SQL Query to Django QuerySet

4👍

You can use QuerySet.filter and QuerySet.update:

chat.objects.filter(nick_from=sender_user, nick_to=receiver_user).update(recd='1')

3👍

I don’t really pay attention to the ORM-specific shims, favouring raw SQL instead. In django, you can easily do this:

chat.objects.raw(''''UPDATE chat  SET recd="1"  WHERE nick_from="%s" AND nick_to="%s"
                       ''' % (sender_user, reciever_user))

If this doesn’t help, do leave a comment.

👤hd1

Leave a comment