Saturday, April 27, 2013

Re: check genre and insert

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] =
                    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
                            report.MovieTitle = line["MovieTitle"]
                            print report.MovieTitle
                            report.IdGenre = line[genres[obj.GenreType]]
                            report.MovieYear = line["MovieYear"]
                            report.MovieDuration = line["MovieDuration"]
    return render_to_response('index.html', {},

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
To post to this group, send email to
Visit this group at
For more options, visit

No comments:

Post a Comment