Hi I want to create new field in sqlalchemy similar to FileField from Django
from sqlalchemy import String
class FileField(String):
"""A mixin that adds field for storing files"""
def __init__(self, length=None, filename='test'):
super().__init__(length=length)
self.filename = filename
def some_method(self):
pass
Then in different file, I have imported FileField, and looks like this:
class NewModel():
"""A user of the app."""
__tablename__ = 'new_model'
logo = Column(FileField(30), unique=True, nullable=False)
def __init__(self, name: str, symbol: str, logo: FileField, **kwargs):
db.Model.__init__(
self,
logo=logo,
**kwargs,
)
migration looks like:
def upgrade():
op.create_table('new_table',
sa.Column('logo', coin_portal.database.FileField(length=30), nullable=False),
But ! :( when using:
- FileField is string and has no .filename property
- Methods are not visible
So my question is how to create a new field which is not just string?