From eba1439ce9ffc49fa63c183b0c39179d31d86eae Mon Sep 17 00:00:00 2001 From: Radek Czajka Date: Tue, 11 May 2010 13:12:06 +0200 Subject: [PATCH] Migration for book count fix. --- .../migrations/0008_fix_shelf_book_count.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 apps/catalogue/migrations/0008_fix_shelf_book_count.py 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 -- 2.20.1