pallets-eco / flask-admin

Simple and extensible administrative interface framework for Flask
https://flask-admin.readthedocs.io
BSD 3-Clause "New" or "Revised" License
5.79k stars 1.57k forks source link

pymongo column_editable_list #1275

Open mrUmberto opened 8 years ago

mrUmberto commented 8 years ago

pymongo (3.2.2) Flask (0.10.1) Flask-Admin (1.4.0)

1) When i add: column_editable_list = ('some_field', 'another_field', ) I got error:

File "../lib/python2.7/site-packages/flask_admin/model/base.py", line 1719, in index_view form = self.list_form()

File "../lib/python2.7/site-packages/flask_admin/model/base.py", line 1208, in list_form return self._list_form_class(get_form_data(), obj=obj)

TypeError: 'NoneType' object is not callable

How i can do fields in listview editable?

2) Examples for pymongo not contains implementation of required abstract methods: _create_ajax_loader(self, name, options), scaffold_filters(self, attr), scaffold_list_form(self, custom_fieldlist=ListEditableFieldList, validators=None), scaffold_list_columns(self), scaffold_form(self)

ljluestc commented 8 months ago
from flask_admin import Admin, BaseView, expose
from flask_admin.contrib.pymongo import ModelView
from pymongo import MongoClient

# Assuming you have a Flask app instance named 'app'
app = Flask(__name__)

# Set up your MongoDB connection
client = MongoClient('localhost', 27017)
db = client['your_database_name']
collection = db['your_collection_name']

# Define your Flask-Admin view class
class MyModelView(ModelView):
    column_list = ('some_field', 'another_field')  # Specify the columns to display in the list view
    column_editable_list = ('some_field', 'another_field')  # Specify the editable columns

# Create an admin interface
admin = Admin(app, name='My Admin')
admin.add_view(MyModelView(collection))

if __name__ == '__main__':
    app.run(debug=True)