本文整理匯總了Python中app.models.Post方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Post方法的具體用法?Python models.Post怎麽用?Python models.Post使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類app.models
的用法示例。
在下文中一共展示了models.Post方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: archive_eligible_submissions
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Post [as 別名]
def archive_eligible_submissions(self, eligible_submissions):
existing_post_ids = set([sub.id for sub in self.db_session.query(Post).filter(
Post.id.in_(list(eligible_submissions.keys())))])
# list of praw objects
to_archive_posts = [eligible_submissions[sid] for sid in eligible_submissions if sid not in existing_post_ids]
new_posts = []
for post in to_archive_posts:
post_info = post.json_dict if("json_dict" in dir(post)) else post['data'] ### TO HANDLE TEST FIXTURES
new_post = Post(
id = post_info['id'],
subreddit_id = post_info['subreddit_id'].strip("t5_"), # janky
created = datetime.datetime.fromtimestamp(post_info['created_utc']),
post_data = json.dumps(post_info))
new_posts.append(new_post)
#self.db_session.add(new_post)
self.db_session.add_retryable(new_posts)
#self.db_session.commit()
示例2: make_shell_context
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Post [as 別名]
def make_shell_context():
return dict(app=app, db=db, User=User, Follow=Follow, Role=Role,
Permission=Permission, Post=Post, Comment=Comment)
示例3: make_shell_context
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Post [as 別名]
def make_shell_context():
return dict(app=app, db=db, User=User, Role=Role, Post=Post, \
Follow=Follow, Permission=Permission, Admin=Admin)
示例4: test_index_with_posts
# 需要導入模塊: from app import models [as 別名]
# 或者: from app.models import Post [as 別名]
def test_index_with_posts(self):
with self.app.app_context():
admin = User.get_by_email('admin@xyz.com')
post = Post(user_id=admin.id, title='Post de prueba', content='Lorem Ipsum')
post.save()
res = self.client.get('/')
self.assertEqual(200, res.status_code)
self.assertNotIn(b'No hay entradas', res.data)