-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
24 lines (19 loc) · 955 Bytes
/
models.py
File metadata and controls
24 lines (19 loc) · 955 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
from flask_sqlalchemy import SQLAlchemy
from datetime import datetime
db = SQLAlchemy()
class User(db.Model):
"""Kullanıcı bilgilerini tutan model."""
id = db.Column(db.Integer, primary_key=True) # Her kullanıcı için benzersiz ID
username = db.Column(db.String(80), unique=True, nullable=False) # Benzersiz ve zorunlu kullanıcı adı
password_hash = db.Column(db.String(256), nullable=False)
def __repr__(self):
return f'<User {self.username}>'
class Message(db.Model):
"""Chat mesajlarını tutan model."""
id = db.Column(db.Integer, primary_key=True)
content = db.Column(db.Text, nullable=False)
timestamp = db.Column(db.DateTime, default=datetime.utcnow)
user_id = db.Column(db.Integer, db.ForeignKey('user.id'), nullable=False)
user = db.relationship('User', backref=db.backref('messages', lazy=True))
def __repr__(self):
return f'<Message {self.id} by {self.user.username}>'