[英]django-import-export how to handle GenericRelations?
我正在使用django-import-export模块导出记录。 但是,我无法导出通用关系。 我只想获取GenericRelation的所有详细信息。
在Github中找到了以下代码段,但该代码行不通。
class DudeResource(resources.ModelResource):
address = fields.Field(
column_name='address',
attribute='address',
widget=widgets.ForeignKeyWidget(Address, 'name')) # use a unique field
class Meta:
model = Dude
fields = ['address']
我的模特儿
Company
|-- Name
|--- Address(Generic Relation)
Address
|--content_type
|--object_id
|--content_object
|--line_1
|--line_2
|--city
|--country
我只需要导入/导出line_1,line_2,城市和国家/地区。 有人可以帮我吗? 谢谢!
您是否尝试过指定像这样的字段...
类DudeResource(resources.ModelResource):
class Meta:
model = Dude
fields = ['address__line_1', 'address__line_2', 'address__city',
'address__line_1', 'address__country', ]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.