Skip to content
Snippets Groups Projects
Commit acd8c926 authored by Odin Johan Vatne's avatar Odin Johan Vatne
Browse files

manage.py helper function for tag categories

parent a96d1616
No related branches found
No related tags found
No related merge requests found
from unicodedata import category
from django.core.management.base import BaseCommand, CommandError
from pasapp.models import TagCategory
class Command(BaseCommand):
help = 'Adds default set of tag categories to the database.'
# (category, )
dataset = [
('Prerequisite Class',), # academic. subject ID/name
('Specialization',), # academic. e.g. "Software Development" or "Databases"
('Subject',), # personal. e.g. "3D Rendering" or "Games"
('Topic of Interest',), # personal. e.g. "Healthcare Systems" or "Sustainability"
('Method',) # personal. e.g. "User Testing", "Literature Review", "Circuit Design", or "Software Prototyping"
]
default_categories = [TagCategory(category=category) for (category,) in dataset]
def handle(self, *args, **options):
succeeded = TagCategory.objects.bulk_create(self.default_categories)
if len(succeeded) == 0:
self.stdout.write(self.style.NOTICE('No categories created.'))
else:
output_string = f'Created {len(succeeded)} categories: ' + ', '.join(cat.category for cat in succeeded)
self.stdout.write(self.style.SUCCESS(output_string))
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment