1

I'm using django-import-export module to export the record. However, I couldn't export the generic relations. I just want to get all the details of GenericRelation.

Found the snippet below in Github but it doesn't work.

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. Can someone help me on this? Thanks!

Wreeecks
  • 2,186
  • 1
  • 33
  • 53

1 Answers1

0

Have you tried specifying the fields like this...

class DudeResource(resources.ModelResource):

class Meta:
    model = Dude
    fields = ['address__line_1', 'address__line_2', 'address__city',
              'address__line_1', 'address__country', ]
Patrick
  • 2,044
  • 1
  • 25
  • 44