I missed that it is message.user.username when pasting it here but anyway it does not work. I checked it's class and it is str
събота, 18 февруари 2017 г., 21:47:27 UTC+2, Daniel Roseman написа: > > On Saturday, 18 February 2017 17:37:49 UTC, Nikoleta Misheva wrote: >> >> I am querying PostgreSQL using *get_object_or_404 * but it throws and >> exception *PairUsers matching query does not exist *and after that *During >> handling of the above exception, another exception >> occurred:django.http.response.Http404: No PairUsers matches the given query >> *when indeed I have a record in my db that matches the query and I am >> sure I am comparing the right values. How should I fix that? >> Here is the corresponding code: >> >> @channel_session_user >> def ws_receive(message): >> username = message.user >> text = json.loads(message['text']).get('text') >> # Use my algorithm here >> score = score_argument.get_rating(text) >> # find the room with our users >> print(username) >> current_room = get_object_or_404(PairUsers, Q(username_a=username) | >> Q(username_b=username)) >> # current_room = PairUsers.objects.filter(Q(username_a=username) | >> Q(username_b=username)) >> >> # check which user you got and send the message to the other >> if current_room.username_b == username: >> current_room.score_b = score >> other_channel = Channel(current_room.reply_channel_a) >> message.reply_channel.send({'text': text}) >> other_channel.send({'text': text}) >> else: >> current_room.score_a = score >> other_channel = Channel(current_room.reply_channel_b) >> message.reply_channel.send({'text': text}) >> other_channel.send({'text': text}) >> >> > Are you sure `message.user` is the same type as `PairUsers.username_a` or > `PairUsers.username_b`? It sounds like one is an instance of User and one > is a character username (although it would be weird to use a username > there, in which case you should really rename the field). > > In any case, you should show your PairUsers model and whatever class > `message` is. > -- > DR. > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9b5044db-51c1-4991-9877-669256aff910%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.