You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
20 lines
623 B
20 lines
623 B
from unidecode import unidecode
|
|
|
|
from django.core.management.base import BaseCommand, CommandError
|
|
from django.db.models import Q
|
|
from django.utils.text import slugify
|
|
from apps.course.models import Course
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = 'Update courses slug'
|
|
|
|
def handle(self, *args, **options):
|
|
courses = Course.objects.filter(Q(slug__isnull=True) | Q(slug=''))
|
|
for course in courses:
|
|
course.slug = slugify(unidecode(course.title[:90]))
|
|
try:
|
|
course.save()
|
|
except:
|
|
course.slug += str(course.id)
|
|
course.save()
|
|
|