[Fixed]-Importing many to many relationship (Django)

1👍

I believe, the problem is with Object creation. I think the following is what you are looking for :

....
....
for i in l[1:]:
        cat_1 = m.Category.objects.get_or_create(category_name = i[4])
        cat_2 = m.Category.objects.get_or_create(category_name = i[11])
....
....
prod.category.add(cat_1)
prod.category.add(cat_2)

Leave a comment