I'm working on an excel file upload in django Using the same method I've populated another model using a xlsx file.But in the second model I cant upload and I'm facing an issue which I mentioned below.
views.py
def import_source(request):
if request.method == "POST":
form = UploadFileForm(request.POST,
request.FILES)
if form.is_valid():
request.FILES['file'].save_to_database(
name_columns_by_row=0,
model=Tracker,
mapdict=['sl_no','dot','branch','sname','snum','can_name','sdetail','main_skills','uname','cus_name','ep_num','day','doi','status','cont_num','email_id','texp','rexp','cu_org','cu_loc','pref_loc','cu_ctc','exp_ctc','notice_period'])
return HttpResponse("OK")
else:
return HttpResponseBadRequest()
else:
form = UploadFileForm()
return render(
request,
'upload_form.html',
{'form': form})
models.py
class Tracker(models.Model):
sl_no = models.IntegerField()
dot = models.DateTimeField()
branch = models.CharField(max_length=200)
sname = models.CharField(max_length=200)
snum = models.CharField(max_length=200)
can_name = models.CharField(max_length=200)
sdetail = models.CharField(max_length=200)
main_skills = models.TextField()
uname = models.CharField(max_length=200)
cus_name = models.CharField(max_length=200)
ep_num = models.CharField(max_length=200,primary_key=True)
day = models.CharField(max_length=200)
doi = models.DateTimeField()
status = models.CharField(max_length=200)
cont_num = models.IntegerField()
email_id = models.EmailField(max_length=200)
texp = models.DecimalField(max_digits=4,decimal_places=2)
rexp = models.DecimalField(max_digits=4,decimal_places=2)
cu_org = models.CharField(max_length=200)
cu_loc = models.CharField(max_length=200)
pref_loc = models.CharField(max_length=200)
cu_ctc = models.DecimalField(max_digits=4,decimal_places=2)
exp_ctc = models.DecimalField(max_digits=4,decimal_places=2)
notice_period = models.IntegerField()
Excel file .xlsx file which I'm tryig to upload
in the above image only the rows with sl_no 1,3,5 are uploaded
result enter image description here
thank you for the support !!@chfw the code worked. actually the problem was with the date format in the excel file. Django accepts yyyy-mm-dd, but the input date was in the format dd-mm-yyyy