Made the proposed change, but what happens is that when will insert the 
movie with a genre that already exists to get the id of that genre, gives 
the following error: ObjectId ('517b15658774a7177cb1280d ') as the id that 
comes from this comes mongodb form.

When the genre does not exist and must enter the new genus, is not to enter.

Does anyone know what I'm doing wrong?
The code is here:
Código (Python):
def csv_upload(request):
    if request.method == 'POST':
            gen = Genre.objects.all()
            genres = dict(Genre.objects.all().values_list('GenreType', 'id'
))
            print genres
            for obj in gen:
                    genres[obj.GenreType] = obj.id
                    print genres[obj.GenreType]
            file = csv.DictReader(request.FILES['file'], delimiter=',',
 quotechar='"')
            for line in file:                      
                    report = Movie()
                    if not line["IdGenre"] in genres:
                            print line["IdGenre"]
                            rep = Genre()
                            rep.GenreType = line["IdGenre"]
                            #print rep.GenreType
                    else:
                            report.MovieTitle = line["MovieTitle"]
                            print report.MovieTitle
                            report.IdGenre = line[genres[obj.GenreType]]
                            report.MovieYear = line["MovieYear"]
                            report.MovieDuration = line["MovieDuration"]
                            report.save()
    return render_to_response('index.html', {},
                                                          context_instance=
RequestContext(request))

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to