我不知道这是否是这样做的正确的方式,但我会做到这一点的before_import功能:
class ProyectosResource(resources.ModelResource):
#repeated_rows = fields.Field()
class Meta:
model = Proyectos
def before_import(self, dataset, dry_run):
"""
Make standard corrections to the dataset before displaying to user
"""
list = []
i = 0
last = dataset.height - 1
while i <= last:
#adding each name to a list
if ("the name is not in the list (take care about capitalizes letters)"):
dataset.rpush((dataset.get_col(0)[0], dataset.get_col(1)[0])) # add this line to the bottom
list = list.append(dataset.get_col(1)[0]) # add the name to the list
dataset.lpop() # erase it from the top (first line)
else :
#the name is already in the list
dataset.lpop() # simply erase it (first line) from the dataset
i = i + 1
这里是Tablib的doc来操作数据集!
您可以在before_import函数中进行每个测试,检查外键关系的ID ...