1 from datetime
import datetime
3 from django
.core
.management
.base
import BaseCommand
4 from django
.utils
.text
import slugify
6 from mygpo
.directory
.models
import Category
, CategoryTag
9 class Command(BaseCommand
):
11 def handle(self
, *args
, **options
):
15 Merges multiple categories into one by listing them as alternative spellings
18 ./manage.py category-merge-spellings <category> <spelling1> [<spelling2> ...]
22 start_time
= datetime
.utcnow()
26 print "Adding new spellings for %s ..." % cat_name
27 category
, created
= Category
.objects
.get_or_create(
28 tags__tag
=slugify(cat_name
),
34 for spelling
in spellings
:
36 tag
, created
= CategoryTag
.objects
.get_or_create(
44 # we just created a new tag-assignedment -- nothing else to do
47 oldcategory
= tag
.category
49 for entry
in oldcategory
.entries
:
50 # todo: this might cause a constraint violation if the
51 # podcast is already a entry of the new category
52 entry
.category
= category
55 tag
.category
= category