category_to_domain.py
469 Bytes
# -*- coding:utf-8 -*-
from django.core.management.base import BaseCommand
from webapp.models import Domain, Meaning
class Command(BaseCommand):
def handle(self, *args, **options):
to_domains()
def to_domains():
for meaning in Meaning.objects.order_by('id'):
print meaning.id
for category in meaning.categories.all():
domain, _ = Domain.objects.get_or_create(name=category.name)
meaning.domains.add(domain)