Implement search
This commit is contained in:
@@ -22,10 +22,23 @@ class Applicant(BaseModel):
|
||||
salutation = TextField(null=False)
|
||||
|
||||
@classmethod
|
||||
def select_table_data(cls):
|
||||
def select_table_data(cls, search_query: str):
|
||||
return (
|
||||
Applicant
|
||||
.select(Applicant.id, Applicant.first_name, Applicant.last_name, ZipCode.id, ZipCode.zip_code, Town.town)
|
||||
.select(
|
||||
Applicant.id,
|
||||
Applicant.first_name,
|
||||
Applicant.last_name,
|
||||
ZipCode.id,
|
||||
ZipCode.zip_code,
|
||||
Town.town
|
||||
)
|
||||
.join(ZipCode, join_type="LEFT JOIN")
|
||||
.join(Town, join_type="LEFT JOIN")
|
||||
.where(
|
||||
(Applicant.first_name.contains(search_query)) |
|
||||
(Applicant.last_name.contains(search_query)) |
|
||||
(ZipCode.zip_code.contains(search_query)) |
|
||||
(Town.town.contains(search_query))
|
||||
)
|
||||
)
|
||||
|
||||
@@ -1,6 +1,20 @@
|
||||
from peewee import Model, MySQLDatabase
|
||||
|
||||
database = MySQLDatabase(None)
|
||||
from lib.Config import DatabaseConfig
|
||||
|
||||
database: MySQLDatabase = MySQLDatabase(None)
|
||||
|
||||
|
||||
def init_database_from_config(config: DatabaseConfig):
|
||||
database.init(
|
||||
host=config['DB_HOST'],
|
||||
user=config['DB_USER'],
|
||||
password=config['DB_PASS'],
|
||||
database=config['DB_NAME'],
|
||||
port=int(config['DB_PORT']),
|
||||
connect_timeout=5,
|
||||
)
|
||||
database.connect()
|
||||
|
||||
|
||||
class BaseModel(Model):
|
||||
|
||||
Reference in New Issue
Block a user