Advertisement
Guest User

Untitled

a guest
Mar 3rd, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. import random
  2. import datetime
  3. from uuid import uuid4
  4.  
  5. from models import db, User, Post, Tag
  6.  
  7. user = User(id=str(uuid4()), username="keger", password="password")
  8. db.session.add(user)
  9. db.session.commit()
  10.  
  11. user = db.session.query(User).first()
  12. tag_one = Tag(id=str(uuid4()), name='Python')
  13. tag_two = Tag(id=str(uuid4()), name='Flask')
  14. tag_three = Tag(id=str(uuid4()), name='SQLALchemy')
  15. tag_four = Tag(id=str(uuid4()), name='JMilkFan')
  16. tag_list = [tag_one, tag_two, tag_three, tag_four]
  17.  
  18. s = "EXAMPLE TEXT"
  19.  
  20. for i in xrange(100):
  21. new_post = Post(id=str(uuid4()), title="Post" + str(i))
  22. new_post.user = user
  23. new_post.publish_date = datetime.datetime.now()
  24. new_post.text = s
  25. new_post.tags = random.sample(tag_list, random.randint(1, 3))
  26. db.session.add(new_post)
  27.  
  28. db.session.commit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement