A CSV-file model backend for Flask-Admin
Project description
flask-admin-csv-model
A CSV-file model backend for Flask-Admin
Warning
- This is a beta version. Not ready for production.
Installation
Open command line and and install using pip:
$ pip install flask-admin-csv-model
Usage
The first step is to initialize an empty admin interface for your Flask app:
from flask import Flask
import flask_admin as admin
app = Flask(__name__)
app.config["SECRET_KEY"] = "123456790"
@app.route("/")
def index():
return '<a href="/admin/">Click me to get to Admin!</a>'
if __name__ == "__main__":
admin = admin.Admin(app, name="Example: Csv")
app.run(debug=True)
Adding Model View:
import pathlib
import csv
from flask_admin_csv_model.contrib.csv import ModelView, Model, TextField
csv_file = pathlib.Path("./example.csv")
with csv_file.open() as f:
dialect = csv.Sniffer().sniff(f.read(1024))
class BaseModel(Model):
class Meta:
file: pathlib.Path = csv_file
dialect: csv.Dialect = dialect
class Data(BaseModel):
first = TextField()
second = TextField()
third = TextField()
fourth = TextField()
fifth = TextField()
class DataAdmin(ModelView):
can_delete = True
can_create = True
can_edit = True
admin = admin.Admin(app, name="Example: Csv")
admin.add_view(DataAdmin(Data))
To run this example
-
Clone the repository:
git clone https://github.com/fholmer/flask-admin-csv-model cd flask-admin-csv-model
-
Create and activate a virtual environment:
python3 -m venv .venv source .venv/bin/activate
-
Install requirements:
pip install -r requirements.txt
-
Run the application::
python app.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
No source distribution files available for this release.See tutorial on generating distribution archives.
Built Distribution
File details
Details for the file flask_admin_csv_model-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: flask_admin_csv_model-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2a7c2194d8285484d9236e45834d678519edc782ee3faa424a6fbbec633a0049 |
|
MD5 | ec18e83037e738212ec0c6850d279195 |
|
BLAKE2b-256 | fe28ec681cbb08a14e3a41990d0a1b3c884d5067823b2d6d69b498a95acdaa60 |