Django rest framework 如何使用excel表格更新数据库中的产品价格?

Django rest framework 如何使用excel表格更新数据库中的产品价格?,django-rest-framework,Django Rest Framework,我有任务要做。 如何从excel工作表更新数据库中的产品价格 例如,我的网站上有一个产品名ABC,我想从excel表格中更新该价格 class Product(models.Model): product_name=models.CharField(max_length=255,blank=True,null=True) product_price=models.CharField(max_length=255,blank=True,null=True) def __s

我有任务要做。 如何从excel工作表更新数据库中的产品价格 例如,我的网站上有一个产品名ABC,我想从excel表格中更新该价格

class Product(models.Model):
    product_name=models.CharField(max_length=255,blank=True,null=True)
    product_price=models.CharField(max_length=255,blank=True,null=True)

    def __str__(self):
        return str(self.product_name)

我假设产品名称在第一列,产品价格在第二列

如果您有任何问题,请告诉我。是的,我无法将其放入我的代码中,请您帮助我,我是这方面的新手。您可以在管理命令中编写这些代码。在这里读一下
import xlrd

file_path = '.../abc.xls'
wb = xlrd.open_workbook(file_path)
wb_sheet = wb.sheet_by_index(0)
total_rows = wb_sheet.nrows

for rownum in range(1, total_rows):
    product_name = wb_sheet.cell(rownum, 0).value
    product_price = wb_sheet.cell(rownum, 1).value
    if product_name and product_price:
        Product.objects.filter(product_name=product_name).update(product_price=product_price)