Initial commit: add compliance_checks table, per-check metadata on assets, and compliance audit trail
This commit is contained in:
37
app/models/assignment.py
Normal file
37
app/models/assignment.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from datetime import datetime
|
||||
from app.extensions import db
|
||||
|
||||
|
||||
class Assignment(db.Model):
|
||||
"""Records the assignment of an asset to a user.
|
||||
|
||||
Every assignment (including past ones) is kept permanently so that
|
||||
asset history is preserved even after a user record is masked.
|
||||
"""
|
||||
__tablename__ = 'assignments'
|
||||
|
||||
id = db.Column(db.Integer, primary_key=True)
|
||||
|
||||
asset_id = db.Column(db.Integer, db.ForeignKey('assets.id'), nullable=False)
|
||||
user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
|
||||
|
||||
assigned_date = db.Column(db.Date, nullable=False, default=datetime.utcnow)
|
||||
returned_date = db.Column(db.Date, nullable=True)
|
||||
|
||||
assigned_by_id = db.Column(db.Integer, db.ForeignKey('admin_users.id'), nullable=True)
|
||||
returned_by_id = db.Column(db.Integer, db.ForeignKey('admin_users.id'), nullable=True)
|
||||
|
||||
notes = db.Column(db.Text, nullable=True)
|
||||
is_active = db.Column(db.Boolean, default=True, nullable=False)
|
||||
|
||||
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
||||
updated_at = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
|
||||
|
||||
assigned_by = db.relationship('AdminUser', foreign_keys=[assigned_by_id])
|
||||
returned_by = db.relationship('AdminUser', foreign_keys=[returned_by_id])
|
||||
|
||||
# Paperwork linked to this assignment
|
||||
paperwork_docs = db.relationship('Paperwork', backref='assignment', lazy='dynamic')
|
||||
|
||||
def __repr__(self):
|
||||
return f'<Assignment asset={self.asset_id} user={self.user_id} active={self.is_active}>'
|
||||
Reference in New Issue
Block a user