Upload Form Django Error (invalid literal for int () with base 10)

0

I have a form with which I want to make an "insert" in one of the models and it gives me the following error and I am not able to know why or debug:

invalid literal for int () with base 10

views.py

def poiUploader(request):
    title = "Photo Uploader"
    text = "Sube tus fotos"
    pois = PoiTxt.objects.filter(lan__lan_id=1)

    context = {
        "template_title": title,
        "template_text": text,
        "pois": pois,
    }

    if request.method == 'POST' and request.FILES['myfile']:
        myfile = request.FILES['myfile']
        fs = FileSystemStorage()
        filename = fs.save(myfile.name, myfile)
        uploaded_file_url = fs.url(filename)
        saved_poi = request.POST.get('poiCode', '')
        poi = Poi.objects.filter(poi_id=saved_poi)
        foto = Photo(pho_url=filename, poi=poi)
        foto.save()
        return render(request, 'poi-uploader.html', {
            'uploaded_file_url': uploaded_file_url
        })

    return render_to_response('poi-uploader.html', context, RequestContext(request))

How should link the poi with the photo with the foreignkey?

Here I leave a link to another thread that I opened from something else and this is my source code.

Thread with my code

    
asked by RuralGalaxy 11.10.2016 в 13:29
source

1 answer

1

Let's see, with this poiCode is a string:

saved_poi = request.POST.get('poiCode', '')
poi = Poi.objects.filter(poi_id=saved_poi)

And this is an int.

poi_id = models.AutoField(db_column='POI_id', primary_key=True)

Try parsing it to int and put the POST you do and the data from within the POST so we can see what else it can be.

    
answered by 11.10.2016 в 16:34