# models.py
#
# Copyright(c) Exequiel Ceasar Navarrete <esnavarrete1@up.edu.ph>
# Licensed under MIT
# Version 0.0.0

from app import db
from slugify import slugify

class Crop(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(80), unique=False)
  crop_type = db.Column(db.String(80), unique=False)
  slug = db.Column(db.String(80), unique=True)

  def __init__(self, name, crop_type):
    self.name = name
    self.crop_type = crop_type
    self.slug = slugify(name)

  def __repr__(self):
    return '<Crop %r>' % self.name

class Region(db.Model):
  id = db.Column(db.Integer, primary_key=True)
  name = db.Column(db.String(80), unique=False)
  slug = db.Column(db.String(80), unique=True)
  region_normalized = db.Column(db.String(80), unique=False)
  region_roman = db.Column(db.String(80), unique=False)
  region_normalized_canonical = db.Column(db.String(160), unique=False)
  region_roman_canonical = db.Column(db.String(160), unique=False)

  def __init__(self, name, region_normalized, region_roman):
    self.name = name
    self.region_normalized = region_normalized
    self.region_roman = region_roman
    self.region_normalized_canonical = "%s (%s)" % (self.name, region_normalized)
    self.region_roman_canonical = "%s (%s)" % (self.name, region_roman)

    # assemble the slug from the canonical roman
    self.slug = slugify(self.region_roman_canonical)

  def __repr__(self):
    return '<Region %r>' % self.region_roman_canonical



Create crop and region model
Create crop and region model
