简体   繁体   English

Django进出口代理模型

[英]Django Import-Export proxy model

i would like to export to a XLS file my data in the Admin, i tried Import-Export (with admin integration) and works great, the problem here is, i'm already using a model, so i need to export a proxy model to XLS, can you help me please?, with this code the model appears, and the import, export menu appears too, but when i try to export or import i got this error: 我想将我在Admin中的数据导出到XLS文件,我尝试了Import-Export(与admin集成)并且运行良好,这里的问题是,我已经在使用模型,因此我需要导出代理模型到XLS,您能帮我吗?使用此代码会显示模型,并且也会出现导入,导出菜单,但是当我尝试导出或导入时出现此错误:

**StopIteration
No exception message supplied**

Admin.py : Admin.py

from django.contrib import admin
from models import *
from django.utils.html import format_html_join
from import_export import resources
from import_export.admin import ImportExportModelAdmin

class ExportarDatosPromo(Promo):
    class Meta:
        proxy = True

class PromoCountResource(resources.ModelResource):
    class Meta:
        model = Promo

class PromoCountAdmin(ImportExportModelAdmin):
    fields = ('name', 'title_description1', 'description1', 'offer', 'coupon_code', 'count')
    readonly_fields = ('name', 'title_description1', 'description1', 'offer', 'coupon_code', 'count')

admin.site.register(ExportarDatosPromo, PromoCountAdmin)

Well, because nobody answer anything, i fix my error. 好吧,因为没有人回答任何问题,所以我修复了我的错误。 The problem is, if you have a Taggit (Django-Taggit) field in your model, Django Import-Export App will not work, so you have to delete the field (and there is no other app for tagging actually working), and import-export will work just fine. 问题是,如果您的模型中有一个Taggit(Django-Taggit)字段,则Django Import-Export应用程序将无法使用,因此您必须删除该字段(并且没有其他用于标记的应用程序实际上可以工作),然后导入-export可以正常工作。

If you want to continue to use django taggit as an app, just put your field in a model with a foreign key to your original model. 如果您想继续使用django taggit作为应用程序,只需将您的字段放入带有原始模型外键的模型中即可。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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