-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTagModel.py
More file actions
42 lines (25 loc) · 761 Bytes
/
TagModel.py
File metadata and controls
42 lines (25 loc) · 761 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
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
class TagModel:
def __init__(self):
from models import Tag
from models import Post
self.Tag = Tag.Tag
self.Post = Post.Post
def tags(self):
tags = self.Tag.query.all()
if tags:
return tags
return False
def addtag(self, name):
from models import db
new_tag = self.Tag(name)
db.session.add(new_tag)
db.session.commit()
return new_tag.Id
def getRepeats(self, id):
u = self.Post.query.join(self.Post.tags).filter(self.Tag.Id == id).count()
return u
def getTagByName(self, name):
tag = self.Tag.query.filter_by(TagName=name).first()
if tag:
return tag.Id
return False