uptd.py
1.56 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
from sqlalchemy import Column, ForeignKey, Integer, String
from opensipkd.pjdl.models import PAD_TABLE_ARGS
from opensipkd.models import User
from opensipkd.pjdl.models.kecamatan import PjdlKecamatan
from . import Base, DefaultModel
from sqlalchemy import (
Column,
String
)
from sqlalchemy.ext.hybrid import hybrid_property
class PjdlUptd(Base, DefaultModel):
__tablename__ = 'uptd'
__table_args__ = PAD_TABLE_ARGS
kode = Column(String(20), nullable=False, unique=True)
nama = Column(String(50), nullable=False, unique=True)
@classmethod
def query_kode(cls, kode):
return cls.query().filter_by(kode=kode)
@classmethod
def query_nama(cls, nama):
return cls.query().filter_by(nama=nama)
@classmethod
def query_register(cls, order_field="nama"):
return cls.query_from(columns=[cls.singkatan, cls.nama]).\
order_by(getattr(cls, order_field))
@classmethod
def get_list(cls):
r = []
q = cls.query().order_by(cls.nama)
for row in q:
g = (str(row.id), f"{row.kode}: {row.nama}")
r.append(g)
return r
class PjdlUptdWilayah(Base, DefaultModel):
__tablename__ = 'uptd_wilayah'
__table_args__ = PAD_TABLE_ARGS
uptd_id = Column(Integer, ForeignKey(PjdlUptd.id))
kecamatan_id = Column(Integer, ForeignKey(PjdlKecamatan.id))
class PjdlUserUptd(Base, DefaultModel):
__tablename__ = 'user_uptd'
__table_args__ = PAD_TABLE_ARGS
uptd_id = Column(Integer, ForeignKey(PjdlUptd.id))
user_id = Column(Integer, ForeignKey(User.id))