Вам не нужно добавлять поле id, оно будет добавлено django по умолчанию
models.py
class QuizCat(models.Model):
c_name = models.CharField(max_length=200)
class Quiz(models.Model):
cat_id = models.ForeignKey(QuizCat, on_delete=models.CASCADE)
name = models.CharField(max_length=200)
views.py
def uploadFile(request):
try:
csv_file = request.FILES["csv_file"]#change csv_file according to your form input name
file_data = csv_file.read().decode("utf-8")
lines = file_data.split("\n")
for line in lines:
fields = line.split(",")
fields = [i.trim() for i in fields ]
name = fields[0]
cat = fields[1]
qcat,created=QuizCat.objects.get_or_create(c_name=cat)
Quiz.objects.get_or_create(cat_id=qcat,name=name)
except e:
raise
return HttpResponse("Success")
CSV
Название викторины, QuizCat name