-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodel.py
More file actions
45 lines (36 loc) · 987 Bytes
/
Copy pathmodel.py
File metadata and controls
45 lines (36 loc) · 987 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from peewee import *
psql_db = PostgresqlDatabase(
'postgres',
user='prabhath',
password='',
host='localhost',
)
class BaseModel(Model):
class Meta:
database = psql_db
db_table = 'city'
table_alias = 'c'
class City(BaseModel):
id = PrimaryKeyField(null=False)
name = CharField(max_length=35)
countrycode = CharField(max_length=3)
district = CharField(max_length=20)
population = BigIntegerField()
@property
def serialize(self):
data = {
'id': self.id,
'name': str(self.name).strip(),
'countrycode': str(self.countrycode).strip(),
'district': str(self.district).strip(),
'population': self.population,
}
return data
def __repr__(self):
return "{}, {}, {}, {}, {}".format(
self.id,
self.name,
self.countrycode,
self.district,
self.population
)