From edbd8ac7b7755fef736df37e50dccf425225345e Mon Sep 17 00:00:00 2001 From: Benjamin Bertrand <benjamin.bertrand@esss.se> Date: Thu, 20 Jul 2017 15:47:40 +0200 Subject: [PATCH] Use tablename in QRCode Use the tablename instead instead of an abbreviation. The scanner client can thus directly get the name of the fields to use. --- app/models.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/app/models.py b/app/models.py index 12b14cb..727b66e 100644 --- a/app/models.py +++ b/app/models.py @@ -129,7 +129,14 @@ class QRCodeMixin: name = db.Column(db.String(50), nullable=False, unique=True) def image(self): - data = ','.join([self.code, str(self.id), self.name]) + """Return a QRCode image to identify a record + + The QRCode includes: + - the table name + - the id of the record + - the name of the record + """ + data = ','.join([self.__tablename__, str(self.id), self.name]) return qrcode.make(data, version=1, box_size=5) def __str__(self): @@ -140,16 +147,14 @@ class QRCodeMixin: class Action(QRCodeMixin, db.Model): - code = 'AC' + pass class Manufacturer(QRCodeMixin, db.Model): - code = 'MA' items = db.relationship('Item', back_populates='manufacturer') class Model(QRCodeMixin, db.Model): - code = 'MO' description = db.Column(db.Text) items = db.relationship('Item', back_populates='model') @@ -158,12 +163,10 @@ class Model(QRCodeMixin, db.Model): class Location(QRCodeMixin, db.Model): - code = 'LO' items = db.relationship('Item', back_populates='location') class Status(QRCodeMixin, db.Model): - code = 'ST' items = db.relationship('Item', back_populates='status') -- GitLab