1 from django.core.management import setup_environ
4 setup_environ(settings)
6 from catalogue.models import Tag, Book
7 from django.db import connection
9 query = 'ALTER TABLE catalogue_tag ADD COLUMN book_count integer NOT NULL DEFAULT 0'
11 cursor = connection.cursor()
14 for shelf in Tag.objects.filter(category='set'):
15 shelf.book_count = len(Book.tagged.with_all(shelf))