ajax_post
bug_creator 3 years ago
parent cbbed8b829
commit 0e2be43b0f

@ -115,6 +115,7 @@ class User(UserMixin, db.Model):
# 发帖、评论与点赞
posts = db.relationship('Post', backref='author', lazy='dynamic', cascade='all, delete-orphan')
questions = db.relationship('Question', backref='author', lazy='dynamic', cascade='all, delete-orphan')
comments = db.relationship('Comment', backref='author', lazy='dynamic', cascade='all, delete-orphan')
# 关注
@ -384,7 +385,18 @@ login_manager.anonymous_user = AnonymousUser
def load_user(user_id):
return User.query.get(int(user_id))
class Question(db.Model):
__tablename__='questions'
id=db.Column(db.Integer,primary_key=True)
title = db.Column(db.Text)
body = db.Column(db.Text)
body_html = db.Column(db.Text)
timestamp = db.Column(db.DateTime, index=True, default=datetime.utcnow)
author_id = db.Column(db.Integer, db.ForeignKey('users.id'))
important = db.Column(db.INT, default=0)
recent_activity = db.Column(db.DateTime, index=True, default=datetime.utcnow())
answers = db.relationship('Post', back_populates='question', cascade='all, delete-orphan', lazy='dynamic')
is_anonymous = db.Column(db.Boolean, default=False)
class Post(db.Model):
__tablename__ = 'posts'
@ -397,6 +409,8 @@ class Post(db.Model):
important = db.Column(db.INT, default=0)
recent_activity = db.Column(db.DateTime, index=True, default=datetime.utcnow())
comments = db.relationship('Comment', back_populates='post', cascade='all, delete-orphan', lazy='dynamic')
question = db.relationship('Question', back_populates='answers', lazy='joined')
question_id = db.Column(db.Integer, db.ForeignKey('questions.id'))
liker = db.relationship('Like', back_populates='liked_post', lazy='dynamic', cascade='all')
is_anonymous = db.Column(db.Boolean, default=False)

@ -455,45 +455,45 @@
{% endif %}
{# hottest #}
<div class="col-sm-12 inner3">
<h4>Hottest Posts</h4>
<ul class="posts list-unstyled">
<li class="hot-post"><a href="{{ url_for('.post', id=posts5[0].id) }}">
<span class="glyphicon glyphicon-fire"></span>
<span>{{ posts5[0].title }}</span>
</a></li>
<li class="hot-post"><a href="{{ url_for('.post', id=posts5[1].id) }}">
<span class="glyphicon glyphicon-fire"></span>
<span>{{ posts5[1].title }}</span>
</a></li>
<li class="hot-post"><a href="{{ url_for('.post', id=posts5[2].id) }}">
<span class="glyphicon glyphicon-fire"></span>
<span>{{ posts5[2].title }}</span>
</a></li>
<li><a href="{{ url_for('.post', id=posts5[3].id) }}"><h4>
<small>4. {{ posts5[3].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[4].id) }}"><h4>
<small>5. {{ posts5[4].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[5].id) }}"><h4>
<small>6. {{ posts5[5].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[6].id) }}"><h4>
<small>7. {{ posts5[6].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[7].id) }}"><h4>
<small>8. {{ posts5[7].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[8].id) }}"><h4>
<small>9. {{ posts5[8].title }}</small>
</h4></a></li>
<li><a href="{{ url_for('.post', id=posts5[9].id) }}"><h4>
<small>10. {{ posts5[9].title }}</small>
</h4></a></li>
</ul>
</ul>
</div>
{# <div class="col-sm-12 inner3">#}
{# <h4>Hottest Posts</h4>#}
{# <ul class="posts list-unstyled">#}
{# <li class="hot-post"><a href="{{ url_for('.post', id=posts5[0].id) }}">#}
{# <span class="glyphicon glyphicon-fire"></span>#}
{# <span>{{ posts5[0].title }}</span>#}
{# </a></li>#}
{# <li class="hot-post"><a href="{{ url_for('.post', id=posts5[1].id) }}">#}
{# <span class="glyphicon glyphicon-fire"></span>#}
{# <span>{{ posts5[1].title }}</span>#}
{# </a></li>#}
{# <li class="hot-post"><a href="{{ url_for('.post', id=posts5[2].id) }}">#}
{# <span class="glyphicon glyphicon-fire"></span>#}
{# <span>{{ posts5[2].title }}</span>#}
{# </a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[3].id) }}"><h4>#}
{# <small>4. {{ posts5[3].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[4].id) }}"><h4>#}
{# <small>5. {{ posts5[4].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[5].id) }}"><h4>#}
{# <small>6. {{ posts5[5].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[6].id) }}"><h4>#}
{# <small>7. {{ posts5[6].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[7].id) }}"><h4>#}
{# <small>8. {{ posts5[7].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[8].id) }}"><h4>#}
{# <small>9. {{ posts5[8].title }}</small>#}
{# </h4></a></li>#}
{# <li><a href="{{ url_for('.post', id=posts5[9].id) }}"><h4>#}
{# <small>10. {{ posts5[9].title }}</small>#}
{# </h4></a></li>#}
{# </ul>#}
{# </ul>#}
{# </div>#}
</div>

@ -91,17 +91,17 @@ def favicon():
# app.secret_key = GeetestLib.VERSION
# User, Role, Students, Permission, Post, Comment, Like, Notification, Transaction, Activity
admin.add_view(ModelView(User, db.session, name="Users", endpoint="users"))
admin.add_view(ModelView(Role, db.session, name="roles", endpoint="roles"))
admin.add_view(ModelView(Students, db.session, name="Studentss", endpoint="Studentss"))
# admin.add_view(ModelView(Permission, db.session, name="Permissions", endpoint="Permissions"))
admin.add_view(ModelView(Post, db.session, name="Posts", endpoint="Posts"))
admin.add_view(ModelView(Comment, db.session, name="Comments", endpoint="Comments"))
admin.add_view(ModelView(Like, db.session, name="Likes", endpoint="Likes"))
admin.add_view(ModelView(Notification, db.session, name="Notifications", endpoint="Notifications"))
admin.add_view(ModelView(Transaction, db.session, name="Transactions", endpoint="Transactions"))
admin.add_view(ModelView(Activity, db.session, name="Activities", endpoint="Activities"))
admin.add_view(FileAdmin("."))
# admin.add_view(ModelView(User, db.session, name="Users", endpoint="users"))
# admin.add_view(ModelView(Role, db.session, name="roles", endpoint="roles"))
# admin.add_view(ModelView(Students, db.session, name="Studentss", endpoint="Studentss"))
# # admin.add_view(ModelView(Permission, db.session, name="Permissions", endpoint="Permissions"))
# admin.add_view(ModelView(Post, db.session, name="Posts", endpoint="Posts"))
# admin.add_view(ModelView(Comment, db.session, name="Comments", endpoint="Comments"))
# admin.add_view(ModelView(Like, db.session, name="Likes", endpoint="Likes"))
# admin.add_view(ModelView(Notification, db.session, name="Notifications", endpoint="Notifications"))
# admin.add_view(ModelView(Transaction, db.session, name="Transactions", endpoint="Transactions"))
# admin.add_view(ModelView(Activity, db.session, name="Activities", endpoint="Activities"))
# admin.add_view(FileAdmin("."))
if __name__ == '__main__':
app.run(debug=True, host='0.0.0.0')

Loading…
Cancel
Save