【发布时间】:2023-03-28 14:11:01
【问题描述】:
我正在使用django-import-export 模块来导出记录。但是,我无法导出通用关系。我只想获取 GenericRelation 的所有详细信息。
在 Github 中找到了下面的 sn-p,但它不起作用。
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、城市和国家。有人可以帮我吗?谢谢!
【问题讨论】:
标签: python django django-import-export django-generic-relations