Compare commits

..

2 Commits

Author SHA1 Message Date
Ching
40129961a0 feat(models): 添加扫码日志记录功能
All checks were successful
continuous-integration/drone/push Build is passing
为了记录扫码操作,添加了一个新的方法add_log到ScanLog模型中。
2025-02-09 18:16:30 +08:00
Ching
d8887eaf5b fix(models): 优化ScanLog查询方法
简化ScanLog模型中查询今天日志的方法,使用更简洁的ORM查询方式。
2025-02-09 18:14:59 +08:00
2 changed files with 6 additions and 4 deletions

1
app.py
View File

@ -531,6 +531,7 @@ def add_to_stream():
stream_id = r.xadd(STREAM_KEY, data)
if data['data'].isnumeric():
models.ScanLog.add_log(data['data'])
bark_push('扫码成功', '条形码 %s' % data['data'])
else:
bark_push('扫码成功', '二维码 %s' % data['data'])

View File

@ -31,10 +31,7 @@ class ScanLog(BaseModel):
today_end = datetime.combine(today, time.max) # End of day (23:59:59.999999)
# Query logs for today
return cls.objects.filter(
scan_at__gte=today_start,
scan_at__lte=today_end
).order_by('-scan_at')
return cls.select().where(cls.scan_at.between(today_start, today_end))
def serialize(self):
# Try to get product info from BarcodeDB
@ -52,6 +49,10 @@ class ScanLog(BaseModel):
'scan_at': self.scan_at
}
@classmethod
def add_log(cls, barcode):
# Add log to database
cls.create(barcode=barcode)
# Create tables