forked from Ctoic/Hostel-Management-System-Using-Flask
-
Notifications
You must be signed in to change notification settings - Fork 0
/
models.py
57 lines (43 loc) · 2.36 KB
/
models.py
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
54
55
56
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime # Added to use datetime for the date column
from flask_login import UserMixin
from datetime import datetime
db = SQLAlchemy()
# models.py
class FeeRecord(db.Model):
id = db.Column(db.Integer, primary_key=True)
student_id = db.Column(db.Integer, db.ForeignKey('student.id'), nullable=False)
amount = db.Column(db.Float, nullable=False)
date_paid = db.Column(db.Date, default=datetime.utcnow)
student = db.relationship('Student', back_populates='fee_records')
# Update Student model to include the relationship
# existing fields...
class Room(db.Model):
id = db.Column(db.Integer, primary_key=True)
room_number = db.Column(db.Integer, unique=True, nullable=False)
students = db.relationship('Student', backref='room', lazy=True)
class Student(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(100), nullable=False)
fee = db.Column(db.Float, nullable=False, server_default='0')
picture = db.Column(db.String(100), nullable=True)
room_id = db.Column(db.Integer, db.ForeignKey('room.id'), nullable=False)
fee_records = db.relationship('FeeRecord', back_populates='student', cascade="all, delete-orphan")
class Expense(db.Model):
id = db.Column(db.Integer, primary_key=True)
item_name = db.Column(db.String(100), nullable=False)
price = db.Column(db.Float, nullable=False)
date = db.Column(db.DateTime, nullable=False, default=datetime.utcnow) # Date column added as per plan
class Issue(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(100), nullable=False)
description = db.Column(db.Text, nullable=False)
status = db.Column(db.String(20), nullable=False)
created_at = db.Column(db.DateTime, nullable=False, default=datetime.utcnow)
class Admin(db.Model, UserMixin):
__tablename__ = 'admin'
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(100), unique=True, nullable=False) # Retain username from the add-admin-login branch
name = db.Column(db.String(100), nullable=False) # Retain name from the master branch
email = db.Column(db.String(100), unique=True, nullable=False) # Retain email from the master branch
password_hash = db.Column(db.String(128), nullable=False) # Use password_hash from add-admin-login