Example #1
0
    text = f.read()
else:
    text = 'nothing'

Topic.objects.all().delete()
for i in range(100):
    t = Topic()
    day = random.randrange(1, 27)
    month = random.randrange(1, 12)
    year = 2010 + random.randrange(1, 8)
    date = datetime.date(year, month, day)
    time = datetime.time(8, 0, tzinfo=timezone.get_current_timezone())
    t.published_at = datetime.datetime.combine(date, time)
    t.title = 'New Article {}/{}/{}'.format(day, month, year)
    t.slug = 'new-article-{}-{}-{}-{}'.format(i, day, month, year)
    t.content = text
    t.author = users[random.randrange(0, len(users) - 1)]
    Topic.save(t)

topics = Topic.objects.all()
for t in topics:
    for i in range(random.randrange(2, 7)):
        u = users[random.randrange(0, len(users) - 1)]
        upvoted = False
        if i > 0:
            topic_upvotes = Upvote.objects.filter(topic=t)
            for el in topic_upvotes:
                if el.upvoter == u:
                    upvoted = True
        if not upvoted:
            up = Upvote(topic=t, upvoter=u)