wilayah.py
1.5 KB
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
46
47
48
49
50
51
52
53
54
from sqlalchemy import (
Column,
Integer,
ForeignKey, UniqueConstraint, String
)
from sqlalchemy.orm import relationship
from ..models import NamaModel, Base, TABLE_ARGS
class Provinsi(Base, NamaModel):
__tablename__ = 'provinsi'
__table_args__ = (
UniqueConstraint('kode'),
TABLE_ARGS
)
class Kota(Base, NamaModel):
__tablename__ = 'kota'
provinsi_id = Column(Integer, ForeignKey(Provinsi.id))
__table_args__ = (
UniqueConstraint('provinsi_id', 'kode'),
TABLE_ARGS
)
provinsi = relationship('Provinsi', backref='kota')
class Kecamatan(Base, NamaModel):
__tablename__ = 'kecamatan'
kota_id = Column(Integer, ForeignKey(Kota.id))
__table_args__ = (
UniqueConstraint('kota_id', 'kode'),
TABLE_ARGS
)
kota = relationship('Kota', backref='kecamatan')
class Kelurahan(Base, NamaModel):
__tablename__ = 'kelurahan'
kecamatan_id = Column(Integer, ForeignKey(Kecamatan.id))
__table_args__ = (
UniqueConstraint('kecamatan_id', 'kode'),
TABLE_ARGS
)
kecamatan = relationship('Kecamatan', backref='kelurahan')
class AlamatModel(object):
alamat = Column(String(255))
alamat2 = Column(String(255))
kelurahan_id = Column(Integer, ForeignKey(Kelurahan.id))
kecamatan_id = Column(Integer, ForeignKey(Kecamatan.id))
kota_id = Column(Integer, ForeignKey(Kota.id))
provinsi_id = Column(Integer, ForeignKey(Provinsi.id))