Data Bindings only have access to attributes of self
. So if you want to access the current user, you need to create a function to expose anvil.users.get_user()
:
class Form1(Form1Template):
# ...
def get_user(self):
return anvil.users.get_user()
Then your data binding can be
len(self.item['players']) < self.item['max_players'] and not self.get_user() in self.item['players']
I think it’s working for you in your first example because len(self.item['players']) > 1
is always True
when you’re testing it. Python doesn’t evaluate parts of boolean expressions it doesn’t need to evaluate to get the result (prioritising from left to right). So anvil.users.get_user()
never gets run.