bluelog icon indicating copy to clipboard operation
bluelog copied to clipboard

关于fakes.py中fake_comments的疑问

Open kaileiwu opened this issue 4 years ago • 1 comments

在生成50条回复时用到 replied=Comment.query.get(random.randint(1, Comment.query.count())), post=Post.query.get(random.randint(1, Post.query.count())) 这样会不会导致生成的replied并不是生成的post的的comment呢?

kaileiwu avatar Oct 11 '20 15:10 kaileiwu

是的,我也发现这个问题了,我的处理方法是:

for i in range(salt):
   post = Post.query.get(random.randint(1, Post.query.count()))
   replied = random.choice(list(Comment.query.with_parent(post)))

   comment = Comment(
       author=fake.name(),
       email=fake.email(),
       site=fake.url(),
       body=fake.sentence(),
       timestamp=fake.date_time_this_year(),
       reviewed=True,
       replied=replied,
       post=post
   )
   db.session.add(comment)
db.session.commit()

不过如果再细抠的话,fake的时间戳也是有问题的,有可能导致reply的comment比被reply的时间comment还早, 以及comment比post也早。。。:)

Update: 刚才发现这个问题在 #1 中就已经提到了:)

yingang avatar Jun 03 '21 09:06 yingang

感谢反馈,已在 https://github.com/greyli/new-bluelog/pull/14 处理。

greyli avatar Sep 17 '23 15:09 greyli