You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by GitBox <gi...@apache.org> on 2019/03/15 03:50:33 UTC

[GitHub] [incubator-superset] francisliyy commented on issue #7023: upload file using model view failed

francisliyy commented on issue #7023: upload file using model view failed
URL: https://github.com/apache/incubator-superset/issues/7023#issuecomment-473149209
 
 
   Is there anybody can help? The code is simple.
   
   (1) Add the following to core.py in the folder models:
   
   `
   from flask import Markup
   from flask_appbuilder.models.mixins import FileColumn
   from flask_appbuilder.filemanager import get_file_original_name
   
   class StaticFile(Model):
   
       __tablename__ = 'static_files'
       id = Column(Integer, primary_key=True)
       file_name = Column(String(250))
       file = Column(FileColumn, nullable=False)
       description = Column(String(150))
   
       def download(self):
           return Markup(
               '<a href="' + url_for('StaticFileModelView.download', filename=str(self.file)) + '">Download</a>')
   
       def file_name(self):
           return get_file_original_name(str(self.file))`
   
   (2) Add the following to core.py in the folder views:
   
   `
   from flask_appbuilder import ModelView
   class StaticFileModelView(ModelView):
       datamodel = SQLAInterface(models.StaticFile)
   
       label_columns = {'file_name': 'File Name', 'download': 'Download'}
       add_columns = ['file', 'description']
       edit_columns = ['file', 'description']
       list_columns = ['file_name', 'download']
       show_columns = ['file_name', 'download']
   
   appbuilder.add_view(
       StaticFileModelView,
       'Upload static File',
       label=__('upload static File'),
       icon='fa-file',
       category='Manage')`

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org