Skip to main content

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

  1. Clone the repository:

    git clone https://github.com/fholmer/flask-admin-csv-model
    cd flask-admin-csv-model
    
  2. Create and activate a virtual environment:

    python3 -m venv .venv
    source .venv/bin/activate
    
  3. Install requirements:

    pip install -r requirements.txt
    
  4. Run the application::

    python app.py
    

Project details


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

flask_admin_csv_model-0.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file flask_admin_csv_model-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for flask_admin_csv_model-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2a7c2194d8285484d9236e45834d678519edc782ee3faa424a6fbbec633a0049
MD5 ec18e83037e738212ec0c6850d279195
BLAKE2b-256 fe28ec681cbb08a14e3a41990d0a1b3c884d5067823b2d6d69b498a95acdaa60

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page