Hi Django Forum
I'm working on a web application that has a page with form set that requires file upload. When I upload the files I get:
Django Version: | 1.9.1 |
---|
Exception Type: | ValueError |
---|
Exception Value: | invalid literal for int() with base 10: '' |
---|
Exception Location: | C:\desarrollo\Python27\lib\site-packages\django\db\models\fields\__init__.py in get_prep_value, line 976 |
---|
Python Executable: | C:\desarrollo\Python27\python.exe |
---|
Python Version: | 2.7.3 |
---|
On this line of code:
study_form_set = DiagnosticStudyFormSet(request.POST, request.FILES, prefix='studies', queryset=DiagnosticStudy.objects.filter(diagnostic__id=pk))
My model:
class DiagnosticStudy(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(verbose_name='Name', max_length=255)
link = models.CharField(verbose_name='Link', max_length=255, blank=True, null=True)
path = models.FileField(upload_to='files', max_length=255, blank=True, null=True)
diagnostic = models.ForeignKey(Diagnostic, blank=True, null=True)
study_type = models.ForeignKey(StudyType, blank=True, null=True)
class Meta:
managed = False
db_table = 't_udm_diagnostic_study'
My forms:
class DiagnosticStudyForm(ModelForm):
class Meta(object):
model = DiagnosticStudy
fields = [ 'id', 'name', 'link', 'path', 'study_type' ]
widgets = {
'id': HiddenInput(attrs={ 'class': 'campo' }),
'name': TextInput(attrs={ 'class': 'campo', 'size': '40', 'onchange': 'validate(this)' }),
'link': TextInput(attrs={ 'class': 'campo', 'size': '40', 'onchange': 'validate(this)' }),
'path': FileInput(attrs={ 'class': 'campo', 'size': '40', 'accept': 'image/gif,image/jpeg,image/pjpeg,image/png,image/tiff,image/x-tiff,application/msword,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/vnd.ms-powerpoint,application/vnd.openxmlformats-officedocument.presentationml.presentation', 'onchange': 'validate(this)' }),
'study_type': HiddenInput(attrs={ 'class': 'campo', 'size': '40', 'onchange': 'validate(this)' }),
}
DiagnosticStudyFormSet = modelformset_factory(DiagnosticStudy, form=DiagnosticStudyForm, extra=5, can_delete=True)
The Form does not have a IntegerField only CharFields and ForeignKeys. Any ideas on how to know which field is generating the error?
Regards,
Néstor