Foreign Key in django migration using django-import-export

倖福魔咒の 提交于 2019-12-05 21:06:21

Either of these two lines work:

ISO2_id = fields.Field( widget=widgets.ForeignKeyWidget(Country, 'ISO2'))

or

ISO2_id = fields.Field(column_name='ISO2_id', attribute='ISO2', widget=widgets.ForeignKeyWidget(Country, 'ISO2'))

using just:

fields = ('ISO2', 'footprint')

gives error

django.db.models.fields.related.RelatedObjectDoesNotExist: CountryFootprint has no ISO2.

The coercing to Unicode error was caused by my not having a string returned from the unicode def:

def __unicode__(self):
    return self.ISO2

should have been

def __unicode__(self):
    return self.ISO2.name

so many coding problems solved by a good nights sleep!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!