从 ms excel 中的一列分解文本并将其插入 Django 模型中的 2 列时,我遇到了问题。这是我的意见.py
class UploadFileForm(forms.Form):
file = forms.FileField()
def import_data(request):
if request.method == "POST":
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
request.FILES['file'].save_to_database(
model=Transaksi,
mapdict=['tanggal', 'kode','unit','keterangan', 'nominal'],
)
return HttpResponse("OK", status=200)
else:
return HttpResponseBadRequest('Gagal Upload')
else:
form = UploadFileForm()
return render(request, 'kastransaksi/transaksi_formupload.html', {'form': form})
这是我的models.py
class Transaksi(models.Model):
tanggal = models.DateField(null=True, blank=True)
kode = models.CharField(max_length=2, null=True, blank=True)
unit = models.CharField(max_length=2, null=True, blank=True)
keterangan = models.CharField(max_length=100, null=True, blank=True)
nominal = models.IntegerField(null=True, blank=True)
我的excel文件只包含三列
tangal keterangan nominal
19/01/2016 944448800010303282-SPP Raihanah Barmim 205000
19/02/2016 944448800010303282-SPP Raihanah Barmim 205000
我想将“keterangan”列中的文本拆分为我的 Django 模型字段,其中有“kode”和“unit”。怎么做?