Added corresponding migration.
main_page = models.BooleanField(_('main page'), default=False, db_index=True, help_text=_('Show tag on main page'))
user = models.ForeignKey(User, blank=True, null=True)
main_page = models.BooleanField(_('main page'), default=False, db_index=True, help_text=_('Show tag on main page'))
user = models.ForeignKey(User, blank=True, null=True)
+ book_count = models.IntegerField(_('book count'))
def has_description(self):
return len(self.description) > 0
def has_description(self):
return len(self.description) > 0
--- /dev/null
+from django.core.management import setup_environ
+import settings
+
+setup_environ(settings)
+
+from catalogue.models import Tag, Book
+from django.db import connection
+
+query = 'ALTER TABLE catalogue_tag ADD COLUMN book_count integer NOT NULL DEFAULT 0'
+
+cursor = connection.cursor()
+cursor.execute(query)
+
+for shelf in Tag.objects.filter(category='set'):
+ shelf.book_count = len(Book.tagged.with_all(shelf))
+ shelf.save()