21 lines
No EOL
730 B
Python
21 lines
No EOL
730 B
Python
from extensions import db
|
|
from datetime import datetime
|
|
|
|
|
|
class Notepad(db.Model):
|
|
id = db.Column(db.Integer, primary_key=True)
|
|
name = db.Column(db.String(100), nullable=False)
|
|
is_public = db.Column(db.Boolean, default=False)
|
|
created_at = db.Column(db.DateTime, default=datetime.utcnow)
|
|
user_id = db.Column(db.Integer, db.ForeignKey('user.id'))
|
|
|
|
notes = db.relationship('Note', backref='notepad', lazy='dynamic', cascade="all, delete-orphan")
|
|
|
|
def to_dict(self):
|
|
return {
|
|
'id': self.id,
|
|
'name': self.name,
|
|
'is_public': self.is_public,
|
|
'owner_id': self.user_id,
|
|
'note_count': self.notes.filter_by(is_hidden=False).count()
|
|
} |