class Seat(db): id = db.fields(db.serial(), db.primary(), db.unique()) name = db.fields(db.string(100), db.not_null()) number = db.fields(db.integer(), db.not_null()) date_created = db.fields(db.datetime(auto_add=True)) cinema_hall = db.fields( db.integer(), db.foreignkey("cinemahall.id", on_delete_cascade=True)) class _Meta_: unique_together = ("name", "cinema_hall", "number")
class Movie(db): id = db.fields(db.serial(), db.primary(), db.unique()) date_created = db.fields(db.datetime(auto_add=True)) name = db.fields(db.string(100), db.not_null(True)) category = db.fields(db.string(100), db.not_null(True)) date_of_release = db.fields(db.datetime(), db.not_null()) rating = db.fields(db.integer(), db.not_null()) length = db.fields(db.time(), db.not_null()) summary = db.fields(db.text(), db.not_null(False))
class Users(db): id = db.fields(db.serial(), db.primary()) date_created = db.fields(db.datetime(auto_add=True)) email = db.fields(db.string(100), db.unique(), db.not_null(True)) password = db.fields(db.string(100), db.not_null(True)) name = db.fields(db.string(100), db.not_null(False)) is_staff = db.fields(db.boolean(default=False), db.not_null()) def find(self, operator, joins, kwargs): if any('report' in item.values() for item in kwargs): dict_={ 'ticket_enddate': datetime.now().strftime("%Y-%m-%d"), 'ticket_startdate': datetime.now().strftime("%Y-%m-%d"), 'total':0 } for item in kwargs: if item.get('field') in ['ticket_enddate', 'ticket_startdate', 'total']: dict_[item.get('field')] = item.get('value') return get_cte_query('user_filtering').format(**dict_) update = [] for item in kwargs: if item.get('field') not in ['ticket_enddate', 'ticket_startdate', 'total', 'report']: update.append(item) return super().find(operator, joins, update)
class ShowTime(db): id = db.fields(db.serial(), db.primary(), db.unique()) date_created = db.fields(db.datetime(auto_add=True)) show_datetime = db.fields(db.datetime(), db.not_null()) movie_id = db.fields( db.integer(), db.not_null(), db.foreignkey("movie.id", on_delete_cascade=True), ) price = db.fields(db.numeric(), db.not_null()) cinema_hall = db.fields( db.integer(), db.foreignkey("cinemahall.id", on_delete_cascade=True)) class _Meta_: unique_together = ("show_datetime", "movie_id") def insert_query(self, records): query = super().insert_query(records) return get_cte_query("showtime_insert").format(query) def clean(self, query): return get_cte_query("clean_showtime").format(**query) def update(self, id, operator, **kwargs): query = super().update(id, operator, **kwargs) return get_cte_query("showtime_insert").format(query)
class Users(db): id = db.fields(db.serial(), db.primary()) date_created = db.fields(db.datetime(auto_add=True)) email = db.fields(db.string(100), db.unique(), db.not_null(True)) password = db.fields(db.string(100), db.not_null(True)) name = db.fields(db.string(100), db.not_null(False)) is_staff = db.fields(db.boolean(default=False), db.not_null()) def find(self, operator, joins, kwargs): if any("report" in item.values() for item in kwargs): dict_ = { "ticket_enddate": datetime.now().strftime("%Y-%m-%d"), "ticket_startdate": datetime.now().strftime("%Y-%m-%d"), "total": 0, } for item in kwargs: if item.get("field") in [ "ticket_enddate", "ticket_startdate", "total", ]: dict_[item.get("field")] = item.get("value") return get_cte_query("user_filtering").format(**dict_) update = [] for item in kwargs: if item.get("field") not in [ "ticket_enddate", "ticket_startdate", "total", "report", ]: update.append(item) return super().find(operator, joins, update)
class Ticket(db): id = db.fields(db.serial(), db.primary(), db.unique()) date_created = db.fields(db.datetime(auto_add=True)) payment_method = db.fields(db.string(10), db.not_null()) user_id = db.fields(db.integer(), db.not_null(), db.foreignkey('users.id', on_delete_cascade=True)) showtime_id = db.fields(db.integer(), db.not_null(), db.foreignkey( 'showtime.id', on_delete_cascade=True)) seat_id = db.fields(db.integer(), db.foreignkey( 'seat.id', on_delete_cascade=True)) class _Meta_: unique_together = ('showtime_id', 'seat_id')
class CinemaHall(db): id = db.fields(db.serial(), db.primary(), db.unique()) date_created = db.fields(db.datetime(auto_add=True)) name = db.fields(db.string(100), db.not_null(), db.unique()) description = db.fields(db.string(100), db.not_null())