Adding foreignKey widget to django-import-export

后端 未结 3 1876
野的像风
野的像风 2020-12-31 14:30

I\'m trying to import data to one of my models, but it\'s failing because I\'m trying to upload the foreignKey Id, not the iterated number that import-export creates.

<
3条回答
  •  孤城傲影
    2020-12-31 14:57

    i think it will help:

    class SolResource(resources.ModelResource):
        school_id = fields.Field()
    
        class Meta:
            # ...
    
        def dehydrate_school_id(self, sol):
            return sol.school_id.school_id # You can get all fields of related model. This is example.
    

提交回复
热议问题