ORM works I think
This commit is contained in:
parent
536a0b2f6d
commit
061ac50612
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -28,6 +28,23 @@ class Person(Base):
|
|||
face = Column('face', LargeBinary)
|
||||
fingerprints = relationship("Fingerprint", foreign_keys='Fingerprint.person_id')
|
||||
|
||||
def serialize(self):
|
||||
prints = []
|
||||
for fingerprint in self.fingerprints:
|
||||
prints.append(fingerprint.serialize())
|
||||
|
||||
data = {
|
||||
"person_id": self.person_id,
|
||||
"timestamp": self.timestamp,
|
||||
"fname": self.fname,
|
||||
"lname": self.lname,
|
||||
"yob": self.yob,
|
||||
"gender": self.gender,
|
||||
"face": self.face,
|
||||
"fingerprints": prints
|
||||
}
|
||||
return data
|
||||
|
||||
class Fingerprint(Base):
|
||||
__tablename__ = "fingerprint"
|
||||
person_id = Column('person_id', Integer, ForeignKey('person.person_id'), primary_key=True)
|
||||
|
|
@ -36,4 +53,13 @@ class Fingerprint(Base):
|
|||
timestamp = Column('timestamp', DateTime, default=datetime.utcnow)
|
||||
fingerprint = Column('fingerprint', LargeBinary)
|
||||
|
||||
def serialize(self):
|
||||
data = {
|
||||
"person_id": self.person_id,
|
||||
"fingerprint_id": self.fingerprint_id,
|
||||
"timestamp": self.timestamp,
|
||||
"fingerprint": self.fingerprint
|
||||
}
|
||||
return data
|
||||
|
||||
Base.metadata.create_all(engine)
|
||||
|
|
@ -3,7 +3,7 @@ import flask
|
|||
import requests
|
||||
import application.config as config
|
||||
import json
|
||||
from application.db import Session, Person
|
||||
from application.db import Session, Person, Fingerprint
|
||||
|
||||
class PersonList(Resource):
|
||||
def post(self, id):
|
||||
|
|
@ -19,14 +19,17 @@ class PersonList(Resource):
|
|||
""" """
|
||||
try:
|
||||
session = Session()
|
||||
person = Person(fname="hi")
|
||||
fingerprint = Fingerprint(fingerprint_id=1)
|
||||
person = Person(fname="hi", fingerprints=[fingerprint])
|
||||
session.add(fingerprint)
|
||||
session.add(person)
|
||||
|
||||
session.commit()
|
||||
|
||||
data = list(session.query(Person).all())
|
||||
arr = []
|
||||
for x in data:
|
||||
arr.append(json.loads(x))
|
||||
arr.append(x.serialize())
|
||||
|
||||
print(arr)
|
||||
return flask.make_response(flask.jsonify({'data': arr}), 200)
|
||||
|
|
|
|||
3
run.py
3
run.py
|
|
@ -2,3 +2,6 @@ from application import app
|
|||
|
||||
app.run(host="0.0.0.0",port='10024', debug=True)
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
BIN
test.sqlite
BIN
test.sqlite
Binary file not shown.
Loading…
Reference in New Issue