From: Radek Czajka Date: Tue, 11 May 2010 11:12:06 +0000 (+0200) Subject: Migration for book count fix. X-Git-Url: https://git.mdrn.pl/wolnelektury.git/commitdiff_plain/eba1439ce9ffc49fa63c183b0c39179d31d86eae?ds=inline Migration for book count fix. --- diff --git a/apps/catalogue/migrations/0008_fix_shelf_book_count.py b/apps/catalogue/migrations/0008_fix_shelf_book_count.py new file mode 100644 index 000000000..b4ee91506 --- /dev/null +++ b/apps/catalogue/migrations/0008_fix_shelf_book_count.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- + +from south.db import db +from django.db import models +from catalogue.models import Tag, Book + +class Migration: + + def forwards(self): + "Write your forwards migration here" + for tag in Tag.objects.filter(user__isnull=False): + books = Tag.intermediary_table_model.objects.get_intersection_by_model(Book, [tag]) + tag.book_count = len(books) + tag.save() + + def backwards(self, orm): + "Write your backwards migration here" + pass