[英]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.