Hello everyone I have created one webpage where I am using Django ‘import_export’ Resource for .xlsfile upload. I am having below fields name in the .xls file as shown below image.
from import_export import resources,widgets,fields
class CTAResource(resources.ModelResource):
AConnectID = fields.Field(column_name=‘AConnectID’, attribute=‘AConnectID’, saves_null_values=False)
class meta:
Model=CTA
Here When I am uploading records from the .xls file and I am keeping AConnectID empty but I am not getting any error and the file is getting uploaded successfully(I am not doing it from the admin site).
Here is my code responsible to upload data.
def CTA_upload(request):
try:
if request.method == 'POST':
movie_resource = CTAResource()
##we will get data in movie_resources####
dataset = Dataset()
new_movie = request.FILES['file']
if not new_movie.name.endswith('xls'):
messages.info(request, 'Sorry Wrong File Format.Please Upload valid format')
return render(request, 'apple/uploadinfosys.html')
messages.info(request, 'Uploading Data Line by Line...')
imported_data = dataset.load(new_movie.read(), format='xls')
count = 1
for data in imported_data:
value = CTA(
data[0],
data[1],
data[2],
data[3],
data[4],
data[5],
data[6],
data[7],
data[8],
)
count = count + 1
value.save()
# messages.info(request, count)
# time.sleep(1)
messages.info(request, 'File Uploaded Successfully...')
except:
messages.info(request,
'Same Email ID has been observed more than once. Except that other records has been added../nPlease Make sure Email field should be unique.')
return render(request, 'app/cta.html')
Can anyone help please help me what mistake I am doing in this.
Also, Can I validate this condition enter link description here inside my class CTAResource(resources.ModelResource): by using import_before?
question from:
https://stackoverflow.com/questions/65856763/saves-null-values-field-in-django-import-and-export-is-not-working 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…