Drop-in replacement of Django admin comes with lots of goodies, fully extensible with plugin support, pretty UI based on Twitter Bootstrap.
BSD 3-Clause "New" or "Revised" License
4.76k
stars
1.41k
forks
source link
使用import插件导入有关联关系数据错误 #643
Open
bigwboy opened 5 years ago
you有关联关系的数据导入错误,希望能解决一下 model.py内容: class Tableone(models.Model): CDN = models.CharField(u'名称', max_length=30) CDN_Remarks = models.TextField(u'备注', null=True, blank=True) class Meta: verbose_name = 'one' verbose_name_plural = 'one' def str(self): return self.CDN
class Tabletwo(models.Model): region = models.CharField(u'子名', max_length=30) CDN = models.ForeignKey('Tableone',on_delete=models.CASCADE,)
adminx.py内容: from .models import Tableone import xadmin from import_export import resources from .models import Tabletwo
class CustomerResource(resources.ModelResource): class Meta: model = Tabletwo fields = ('id', 'region','CDN__CDN',)
class CDNTableXAdmin(object): list_display = ('CDN',) xadmin.site.register(Tableone,CDNTableXAdmin)
class RegionTableXAdmin(object): list_display = ('region','CDN',) import_export_args = {'import_resource_class': CustomerResource, 'export_resource_class': CustomerResource} xadmin.site.register(Tabletwo,RegionTableXAdmin) 导入文件内容: 报错信息: