completed - todo cleanup requirements.txt
This commit is contained in:
@@ -42,11 +42,17 @@ class Comment(db.Model):
|
||||
message = db.Column(db.String(140))
|
||||
paragraph_id = db.Column(db.Integer, db.ForeignKey('paragraph.id'))
|
||||
post_id = db.Column(db.String(32), db.ForeignKey('post.id'))
|
||||
# pub_date = db.Column(db.DateTime)
|
||||
paragraph = db.relationship('Paragraph',backref=db.backref('comments', lazy='dynamic'))
|
||||
|
||||
def __init__(self, name,message):
|
||||
def __init__(self, name,message,paragraph_id,post_id, pub_date=None):
|
||||
self.name = name
|
||||
self.message = message
|
||||
self.post_id = post_id
|
||||
self.paragraph_id = paragraph_id
|
||||
if pub_date is None:
|
||||
pub_date = datetime.utcnow()
|
||||
# self.pub_date = pub_date
|
||||
|
||||
def __repr__(self):
|
||||
return '<Comment %r>' % self.name
|
||||
|
||||
19
app/views.py
19
app/views.py
@@ -15,8 +15,9 @@ from models import Post,Paragraph,Comment
|
||||
manager = APIManager(app, flask_sqlalchemy_db=db)
|
||||
# Create API endpoints, which will be available at /api/<tablename> by
|
||||
# default. Allowed HTTP methods can be specified as well.
|
||||
manager.create_api(Post, methods=['GET'],results_per_page=5)
|
||||
manager.create_api(Paragraph, methods=['GET'])
|
||||
manager.create_api(Post, methods=['GET'],exclude_columns=['paragraphs'],results_per_page=5)
|
||||
manager.create_api(Post, methods=['GET'],results_per_page=None,collection_name='post_para')
|
||||
manager.create_api(Paragraph, methods=['GET'],results_per_page=None)
|
||||
manager.create_api(Comment, methods=['GET','POST'])
|
||||
|
||||
restapi = Api(app)
|
||||
@@ -26,9 +27,9 @@ restapi = Api(app)
|
||||
def index():
|
||||
return app.send_static_file('index.html')
|
||||
|
||||
class CreatePost(Resource):
|
||||
@restapi.route('/api/post_misc')
|
||||
class PostMisc(Resource):
|
||||
def post(self):
|
||||
print('hello')
|
||||
try:
|
||||
post_data = json.loads(request.data)
|
||||
title = post_data['title']
|
||||
@@ -42,10 +43,16 @@ class CreatePost(Resource):
|
||||
db.session.commit()
|
||||
return {'post_id':p_e.id}
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return restapi.abort(400,'Invalid data')
|
||||
|
||||
restapi.add_resource(CreatePost,'/api/create_post')
|
||||
# @app.route('/api/post_misc')
|
||||
# def get_post():
|
||||
# post_id = request.args.get('post_id')
|
||||
# print(post_id)
|
||||
# p_e = Post.query.get(post_id)
|
||||
# return {'paragraphs':p_e.paragraphs}
|
||||
|
||||
# restapi.add_resource(PostMisc,'/api/post_misc')
|
||||
# @app.route('/api/create_post',methods=['POST'])
|
||||
# def create_post():
|
||||
# title = request.form.get('title',None);
|
||||
|
||||
Reference in New Issue
Block a user