コード例 #1
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Permission(db.Model):

	__tablename__ = 'permissions'
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(20), unique=True, nullable=False)

	def __repr__(self):
		return f"<Permission (id={self.id}, name={self.name})>"
コード例 #2
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Setting(db.Model):

	__tablename__ = 'settings'
	name = db.Column(db.String(64), primary_key=True, unique=True, nullable=False)
	value = db.Column(db.String(64))
	autoload = db.Column(db.Boolean, default=False)

	def __repr__(self):
		return f"<Setting ({self.name})>"
コード例 #3
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Role(db.Model):

	__tablename__ = 'roles'
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(20), unique=True, nullable=False)
	
	users = db.relationship('User', backref='role', lazy=True)
	permissions = db.relationship('Permission', secondary=role_perm, lazy='subquery', backref=db.backref('roles', lazy=True))

	def __repr__(self):
		return f"<Role (id={self.id}, name={self.name})>"
コード例 #4
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Category(db.Model):

	__tablename__ = 'categories'
	id = db.Column(db.Integer, primary_key=True)
	name = db.Column(db.String(20), unique=True, nullable=False)
	slug = db.Column(db.String(180), unique=True, nullable=False)
	parent_cat = db.Column(db.Integer, db.ForeignKey('categories.id'))

	getSubCategories = db.relationship('Category', remote_side='Category.id', backref=db.backref('getParentCategory', lazy=True))

	def __repr__(self):
		return f"<Category (id={self.id}, name={self.name})>"
コード例 #5
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Post(db.Model):

	__tablename__ = 'posts'
	id = db.Column(db.Integer, primary_key=True)
	title = db.Column(db.String(180), nullable=False)
	slug = db.Column(db.String(180), unique=True, nullable=False)
	content = db.Column(db.Text)
	status = db.Column(db.Integer, default=1)
	user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
	updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
	created = db.Column(db.DateTime, default=datetime.utcnow)

	comments = db.relationship('Comment', backref=db.backref('getPost', lazy=True))
	categories = db.relationship('Category', secondary=Post_category, lazy='subquery', backref=db.backref('getPosts', lazy=True))

	def __repr__(self):
		return f"<Post (id={self.id})>"
コード例 #6
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Comment(db.Model):

	__tablename__ = 'comments'
	id = db.Column(db.Integer, primary_key=True)
	content = db.Column(db.Text)
	status = db.Column(db.Integer, default=1)
	updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
	created = db.Column(db.DateTime, default=datetime.utcnow)

	user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
	post_id = db.Column(db.Integer, db.ForeignKey('posts.id'), nullable=False)
	parent_comm = db.Column(db.Integer, db.ForeignKey('comments.id'), nullable=True)

	getSubComments = db.relationship('Comment', remote_side='Comment.id', backref=db.backref('getParentComment', lazy=True))

	def __repr__(self):
		return f"<Comment (id={self.id})>"
コード例 #7
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class Page(db.Model):

	__tablename__ = 'pages'
	id = db.Column(db.Integer, primary_key=True)
	title = db.Column(db.String(180), nullable=False)
	slug = db.Column(db.String(180), unique=True, nullable=False)
	status = db.Column(db.Integer, default=1)
	updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
	created = db.Column(db.DateTime, default=datetime.utcnow)


	def __repr__(self):
		return f"<Page (id={self.id})>"
コード例 #8
0
ファイル: models.py プロジェクト: medram/simple_python_blog
class User(db.Model, UserMixin):

	__tablename__ = 'users'
	id = db.Column(db.Integer, primary_key=True)
	fname = db.Column(db.String(25))
	lname = db.Column(db.String(25))
	username = db.Column(db.String(25), unique=False, nullable=False)
	email = db.Column(db.String(180), unique=True, nullable=False)
	password = db.Column(db.String(255), nullable=False)
	token = db.Column(db.String(40), unique=True, nullable=False)
	status = db.Column(db.Integer, default=1)
	profile_img = db.Column(db.String(40))
	role_id = db.Column(db.Integer, db.ForeignKey('roles.id'), nullable=False)
	updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
	created = db.Column(db.DateTime, default=datetime.utcnow)

	posts = db.relationship('Post', backref='getUser', lazy=True)
	comments = db.relationship('Comment', backref=db.backref('getUser', lazy=True))

	def getProfileImg(self):
		default_profile = 'default.png'
		#profileURI = os.path.join(current_app.static_url_path, 'imgs/profiles', self.profile_img if self.profile_img else default_profile)
		profileURI = url_for('static', filename=f'imgs/profiles/{(self.profile_img if self.profile_img else default_profile)}')
		return profileURI

	def getBadge(self):
		colors = {'author': 'aqua', 'owner': 'green', 'admin': 'yellow'}
		color = None
		try:
			color = colors[self.role.name]
		except:
			pass
		return Markup(f'<span class="badge bg-{color}">{self.role.name}</span>')

	def __repr__(self):
		return f"<User (id={self.id})>"
コード例 #9
0
ファイル: models.py プロジェクト: medram/simple_python_blog
	def getBadge(self):
		colors = {'author': 'aqua', 'owner': 'green', 'admin': 'yellow'}
		color = None
		try:
			color = colors[self.role.name]
		except:
			pass
		return Markup(f'<span class="badge bg-{color}">{self.role.name}</span>')

	def __repr__(self):
		return f"<User (id={self.id})>"


Post_category = db.Table('post_category',
		db.Column('post_id', db.Integer, db.ForeignKey('posts.id'), primary_key=True,),
		db.Column('category_id', db.Integer, db.ForeignKey('categories.id'), primary_key=True)
	)

class Post(db.Model):

	__tablename__ = 'posts'
	id = db.Column(db.Integer, primary_key=True)
	title = db.Column(db.String(180), nullable=False)
	slug = db.Column(db.String(180), unique=True, nullable=False)
	content = db.Column(db.Text)
	status = db.Column(db.Integer, default=1)
	user_id = db.Column(db.Integer, db.ForeignKey('users.id'), nullable=False)
	updated = db.Column(db.DateTime, default=datetime.utcnow, onupdate=datetime.utcnow)
	created = db.Column(db.DateTime, default=datetime.utcnow)