1
from django.db import connection
3
from pybb.models import Forum, Topic
5
DESCRIPTION = 'Add and populate post_count fields to Forum and Topic models'
8
cur = connection.cursor()
10
print 'Altering forum table'
11
cur.execute("ALTER TABLE pybb_forum ADD post_count INT NOT NULL DEFAULT 0")
13
print 'Altering topic table'
14
cur.execute("ALTER TABLE pybb_topic ADD post_count INT NOT NULL DEFAULT 0")
16
print 'Populating post_count of topics'
17
for topic in Topic.objects.all():
18
topic.post_count = topic.posts.all().count()
21
print 'Populating post_count of forums'
22
for forum in Forum.objects.all():
23
forum.post_count = sum(x.post_count for x in forum.topics.all())