Skip to content

Instantly share code, notes, and snippets.

@marcelcaraciolo
Created June 25, 2013 14:19
Show Gist options
  • Save marcelcaraciolo/5858817 to your computer and use it in GitHub Desktop.
Save marcelcaraciolo/5858817 to your computer and use it in GitHub Desktop.
def _save_categories(curso_id_in_supplier, category):
from shop.models import Category, CourseCategories, Course
c_c = CourseCategories()
c_c.course = Course.objects.get(id_in_supplier=curso_id_in_supplier, supplier=IOB)
try:
c_c.category = Category.objects.get(slug=category)
except Category.DoesNotExist:
ct = Category()
ct = category
ct.save()
c_c.category = ct
except Category.MultipleObjectsReturned:
c_c.category = Category.objects.filter(slug=category)[0]
cc, created = CourseCategories.objects.get_or_create(course=c_c.course,
category=c_c.category)
return cc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment