The game engine provides me with the Player class, which has a uniqueid read-only property to identify players. I would like to βconvertβ this to an SQLAlchemy Column so that I can query the players this way:
query = session.query(Player).filter(Player.uniqueid=='STEAM_0:0:1234567') player = query.one_or_none() if player is None: player = Player(uniqueid='STEAM_0:0:1234567')
Here my class is as follows:
class Player(game.Player, db.Model): _uniqueid = Column('uniqueid', String(21), unique=True, nullable=False) def __init__(self, index, **kwargs): game.Player.__init__(index)
Further, I would like to create a read-only interface for _uniqueid , so API users will no longer be able to write a variable (well, they can through _uniqueid , but this depends on their responsibility, since access to it must occur through non-private uniqueid ).
I am thinking of overriding the original uniqueid new one:
@property def uniqueid(self): return self._uniqueid
It is read-only and βhidesβ the original _uniqueid , not allowing anyone to write on it unless they intentionally turn to the closed one (I will not even list it in the documentation, private).
The only problem is that it completely overrides the old one, which means that my __init__ _uniqueid=self.uniqueid will not work due to self.uniqueid using the new getter, not the old one.
So, I want to convert a read-only property to a read-only message that can be used to query using SQLAlchemy. Is this possible, and if, how?
Markus meskanen
source share