简体   繁体   English

django-import-export如何处理GenericRelations?

[英]django-import-export how to handle GenericRelations?

I'm using django-import-export module to export the record. 我正在使用django-import-export模块导出记录。 However, I couldn't export the generic relations. 但是,我无法导出通用关系。 I just want to get all the details of GenericRelation. 我只想获取GenericRelation的所有详细信息。

Found the snippet below in Github but it doesn't work. 在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']

My Models 我的模特儿

Company
|-- Name
|--- Address(Generic Relation)

Address
|--content_type
|--object_id
|--content_object
|--line_1
|--line_2
|--city
|--country

I just need to import/export line_1, line_2, city, and country. 我只需要导入/导出line_1,line_2,城市和国家/地区。 Can someone help me on this? 有人可以帮我吗? Thanks! 谢谢!

Have you tried specifying the fields like this... 您是否尝试过指定像这样的字段...

class DudeResource(resources.ModelResource): 类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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM