Giter Club home page Giter Club logo

mvc-flask-pymongo's Introduction

Model Based Validator design for Flask (Python) and Mongo DB

Model based custom validation for flask (python). Use Flask server and mongo db. Integrate with any SPA API development.

Create virtual environment and install requirements

pip install -r requirements.txt

Configure Database

From db_config.json configure datbase url, name, user and password

 {
   "db": {
            "url" : "mongodb://localhost:27017/",
            "name" :"db_name",  
            "user" :"",
            "password" :""
    }
 }

In model update collection name and desire fields name and fields type. For example see todo model file

From model folder write your individual model and configure db collection name, fields name and fields type

Example

In todo model update collection name, fields name and fields type
collection_name = 'todos'   # collection name
fields = {   
    "title"     : "string",
    "body"      : "string",
    "created"   : "datatime"
} 
Update required fields, optional fields from todo model
create_required_fields = []  # example create_required_fields = ["title", "body"]
create_optional_fields = []  # example create_required_fields = ["created"]
update_required_fields = []
update_optional_fields = []

Example

create_required_fields = ["title", "body"] 
create_optional_fields = []  
update_required_fields = ["title", "body"]
update_optional_fields = []

In Database insert, find , find_by_id, update and delete methods are generalize methods.

Those methods are call from model

  • insert method store data to database after confirm validation from model
  • find method retries all data from mongo database
  • find_by_id method retries back a single search data
  • update method store updated data to database with corresponding id
  • and delete method delete data from database with corresponding id

List of Todo Routes

Request Endpoint Details
GET http://127.0.0.1:5000/todos Get All
GET http://127.0.0.1:5000/todos/todo_id Get Single Id
POST http://127.0.0.1:5000/todos Insert One
PUT http://127.0.0.1:5000/todos/todo_id Update One
DELETE http://127.0.0.1:5000/todos/todo_id Delete One
  • To see route list type cli flask routes

Lets run the App

python app.py 

mvc-flask-pymongo's People

Contributors

akmamun avatar arif-ibrahim avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

mvc-flask-pymongo's Issues

Boolean support?

Hello. Thanks for this!

What is required to support boolean values?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.