dashwood.net -

Ryan Stefan's Micro Blog

Object Oriented Flask: An Overdue Update

Nov 262018

I was on vacation for a while, thus my daily blog suffered some... neglect. However, I did do a lot of coding during this time on Review Mill. I've begun refactoring my database completely using an open source tool called Visual Alchemist. It needs to be updated so that it works with the most recent SQLalchemy version, but it does put everything in classes and makes it really easy to visualize the entire database to a project. 

undefined

Now, armed with proper object oriented pythonic database classes, I'm applying this database to a skeleton flask project with a user system. The one I found is called Flask Base and seems to have a very cutting edge development style using blueprints and all kinds of optimization features. Here are some of the perks to Flask Base:

  • Blueprints
  • User and permissions management
  • Flask-SQLAlchemy for databases
  • Flask-WTF for forms
  • Flask-Assets for asset management and SCSS compilation
  • Flask-Mail for sending emails
  • gzip compression
  • Redis Queue for handling asynchronous tasks
  • ZXCVBN password strength checker
  • CKEditor for editing pages

It is a bit of a headache reading through all of the code so that I understand how it works, but at least I actually do understand it for once and it will help me build my app with the proper techniques and structures.

 

Here's some of the modified SQLAlchemy code:

class Amazon_Product(db.Model):
    __tablename__ = "amazon_products"
    asin = db.Column(db.Text(15), primary_key=True, unique=True)
    category = db.Column(db.Text(255))
    category_path = db.Column(db.Text(255))
    company = db.Column(db.Text(255))
    rating = db.Column(db.Float)
    num_reviews = db.Column(db.Integer)
    prod_desc = db.Column(db.Text(255))
    img_path = db.Column(db.Text(255))
    img_url = db.Column(db.Text(255))
    price = db.Column(db.Text(255))
    url = db.Column(db.Text(255))

    review_meta = db.relationship("Review_Meta")
    milled_reviews = db.relationship("Milled_Reviews")
    comments = db.relationship("Comment")
    tags = db.relationship("Prod_Tag")

Comments