'Flask-sqlalchemy, good practices for generating unique key from row?
Solution 1:[1]
You don't need to create extra column for that. Dependend how you create your models, you can use composite primary key:
class Model(Base):
__tablename__ = "model"
article = Column(Integer, primary_key=True)
telegramID = Column(Integer, primary_key=True)
type_settings = Column(String, primary_key=True)
...
@property
def composite_key(self):
return (self.article, self.telegramID, self.type_settings, ...)
Now to get the specific row for given key you can use simple query
row = db.query(Model).get((article, telegramID, type_settings, ...))
print(row.composite_key)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |

