本文整理汇总了Python中forum.models.Post.created_on方法的典型用法代码示例。如果您正苦于以下问题:Python Post.created_on方法的具体用法?Python Post.created_on怎么用?Python Post.created_on使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forum.models.Post
的用法示例。
在下文中一共展示了Post.created_on方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: migrate_forum
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import created_on [as 别名]
def migrate_forum(db):
category_id_map = {}
for cat in fetch_all(db, "GDN_Category"):
slug = CATEGORY_MAP.get(cat["UrlCode"], None)
if not slug:
continue
category_id_map[cat["CategoryID"]] = (Category.objects.get(slug=slug), cat["UrlCode"])
copied_posts, copied_comments = 0, 0
for thread in fetch_all(db, "GDN_Discussion"):
if thread["CategoryID"] not in category_id_map:
continue
cat, urlcode = category_id_map.get(thread["CategoryID"])
new_post = Post(
pk=thread["DiscussionID"],
category=cat,
title=(thread["Name"] if CATEGORY_MAP[urlcode] != "old" else ("[%s] " % urlcode) + thread["Name"]),
user=User.objects.get(pk=thread["InsertUserID"]),
created_on=thread["DateInserted"],
text=thread["Body"],
)
new_post.save()
new_post.created_on = thread["DateInserted"]
new_post.save()
patch("forum-post-%d" % new_post.id, thread["DateInserted"])
comments = fetch_all(db, "GDN_Comment", DiscussionID=thread["DiscussionID"])
for comment in comments:
user = User.objects.get(pk=comment["InsertUserID"])
new_comment = Comment(
user=user,
content_type=ContentType.objects.get_for_model(Post),
object_pk=new_post.pk,
comment=comment["Body"],
site_id=settings.SITE_ID,
submit_date=comment["DateInserted"],
)
new_comment.save()
patch("comment-%d" % new_comment.id, comment["DateInserted"])
copied_comments += 1
copied_posts += 1
if copied_posts % 10 == 0:
print "%d posts. %d comments." % (copied_posts, copied_comments)
print "%d posts. %d comments." % (copied_posts, copied_comments)