Skip to content

Seed categories

hypha.apply.categories.management.commands.seed_categories

Command

Bases: BaseCommand

help class-attribute instance-attribute

help = 'Pre-seeds the global application categories. Application Forms and Fund Types seeding depend on this.'

handle

handle(*args, **options)
Source code in hypha/apply/categories/management/commands/seed_categories.py
@transaction.atomic
def handle(self, *args, **options):
    for item in CATEGORIES:
        category, created = Category.objects.get_or_create(name=item["category"])
        if created:
            self.stdout.write(
                self.style.SUCCESS(f"Category {item['category']} created")
            )
        term, created = Option.objects.get_or_create(
            value=item["name"], category=category
        )
        if created:
            self.stdout.write(
                f"Term {item['name']} added to category {item['category']}"
            )