~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/migrations/001_forum_updated.py

  • Committer: Holger Rapp
  • Date: 2009-02-25 16:55:36 UTC
  • Revision ID: sirver@kallisto.local-20090225165536-3abfhjx8qsgtzyru
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.db import connection
 
2
 
 
3
from pybb.models import Forum, Topic
 
4
 
 
5
DESCRIPTION = 'Add updated column to forum table'
 
6
 
 
7
def migrate():
 
8
    cur = connection.cursor()
 
9
 
 
10
    print 'Altering forum table'
 
11
    cur.execute("ALTER TABLE pybb_forum ADD updated DATETIME NULL")
 
12
 
 
13
    print 'Fixing updated values of forums'
 
14
    for forum in Forum.objects.all():
 
15
        try:
 
16
            topic = forum.topics.all().order_by('-updated')[0]
 
17
        except IndexError:
 
18
            pass
 
19
        else:
 
20
            forum.updated = topic.updated
 
21
            forum.save()
 
22
 
 
23