Discussed in #1086
Originally posted by satinfive May 21, 2023
Hi!
I am not sure if I am doing things right, that's why I wanted to ask before opening this as an issue.
I have defined two models: Battle and User:
class User(ormar.Model):
class Meta(base.BaseMeta):
tablename = "users"
queryset_class = UserQuerySet
id: str = ormar.String(primary_key=True, max_length=50)
username: str = ormar.String(max_length=255)
team_id: str = ormar.String(max_length=50)
class Battle(ormar.Model):
class Meta(base.BaseMeta):
tablename = "battles"
id: int = ormar.Integer(primary_key=True, autoincrement=True)
player1: models.User = ormar.ForeignKey(models.User, related_name="player1")
player2: models.User = ormar.ForeignKey(models.User, related_name="player2")
current_status: BattleStatus = ormar.String(max_length=100, default=BattleStatus.ONGOING.value, choices=list(BattleStatus), )
winner: Optional[models.User] = ormar.ForeignKey(models.User, nullable=True, related_name="winner")
Given those, I have user_a as an instance of User. I want to fetch all users in database that are not in a battle with given user_a.
I tried to execute the following query:
users_available_for_battle = await User.objects.available_in_workspace(
team_id=team_id).exclude(
id=user_a_id).select_related(
['player1', 'player2']).exclude(
player1__id=user_a_id).exclude(
player2_iid=user_a_id)
But I am getting all the time KeyError: player1 .
It's possible that I am not doing the query correctly, so I'd like some feedback to know if it's that the case or there is something that is not working properly in the library.
Thanks!
Discussed in #1086
Originally posted by satinfive May 21, 2023
Hi!
I am not sure if I am doing things right, that's why I wanted to ask before opening this as an issue.
I have defined two models:
BattleandUser:Given those, I have
user_aas an instance of User. I want to fetch all users in database that are not in a battle with givenuser_a.I tried to execute the following query:
But I am getting all the time
KeyError: player1.It's possible that I am not doing the query correctly, so I'd like some feedback to know if it's that the case or there is something that is not working properly in the library.
Thanks!