Delete Data
#\controllers\register.py
import config, re, json, datetime
from bottle import template, route, request, redirect
from models import customerdb, bicycledb, registerdb

config.kargs['sortIndex'] = 0

@route('/register')
def displayRegister():
  config.kargs['registers'] = json.dumps(registerdb.select())
  return template('register', data=config.kargs)

@route('/registerForm')
def getRegisterForm():
  config.kargs['bicycles'] = json.dumps(bicycledb.select())
  config.kargs['customers'] = json.dumps(customerdb.select())
  return template('registerform', data=config.kargs)

@route('/register', method="POST")
def insertToRegister():
  brand = json.loads(request.forms.get("fbikelist"))
  customer = json.loads(request.forms.get("fcustomerlist"))
  bicycledb.amountMinus(brand[0])
  registerdb.insert(brand[0], customer[1], brand[1], (datetime.date.today()).strftime('%Y-%m-%d'), '1990-07-30')
  redirect('/register')

@route('/register/returndate/<id>/<bikeid>')
def editReturnDate(id, bikeid):
  registerdb.setReturnDate((datetime.date.today()).strftime('%Y-%m-%d'), id)
  bicycledb.amountPlus(bikeid)
  redirect('/register')

@route('/register/delete/<id>')
def deleteRegister(id):
  registerdb.delete(id)
  redirect('/register')
#\models\registerdb.py
import sqlite3

def insert(*register):
  conn = sqlite3.connect('sqlite.db')
  cursor = conn.cursor()

  sql ='''CREATE TABLE IF NOT EXISTS REGISTER(
    ID INT,
    CUSTOMER TEXT,
    BRAND TEXT,
    RENTDATE DATE,
    RETURNDATE DATE
  )
  '''

  cursor.execute(sql)

  cursor.execute("INSERT INTO REGISTER VALUES (?, ?, ?, ?, ?)", register)
  
  conn.commit()
  conn.close()


def select():
  conn = sqlite3.connect('sqlite.db')
  cursor = conn.cursor()

  sql ='''CREATE TABLE IF NOT EXISTS REGISTER(
    ID INT,
    CUSTOMER TEXT,
    BRAND TEXT,
    RENTDATE DATE,
    RETURNDATE DATE
  )
  '''

  cursor.execute(sql)

  cursor.execute("SELECT ROWID, * from REGISTER")

  registers = cursor.fetchall()
  
  conn.commit()
  conn.close()

  return registers

def setReturnDate(*args):
  conn = sqlite3.connect('sqlite.db')
  cursor = conn.cursor()

  sql = "UPDATE REGISTER SET RETURNDATE=? WHERE ROWID=?"
  
  cursor.execute(sql, args)
  
  conn.commit()
  conn.close()

def delete(id):
  conn = sqlite3.connect('sqlite.db')
  cursor = conn.cursor()

  cursor.execute("DELETE FROM REGISTER WHERE ROWID=?", (id,))

  conn.commit()
  conn.close()

GitHub: https://github.com/Sokhavuth/Rental-Bicycle-App
Heroku: https://khmerweb-rba.herokuapp.com/