简体   繁体   English

如何从 django-import-export 获取文件?

[英]How to get file from django-import-export?

I want to use groupby() function from pandas, but dont know how to get file before export.我想从 pandas 使用 groupby() function,但不知道如何在导出前获取文件。 I've tried dehydrate, but I dont think it's what i want.我试过脱水,但我不认为这是我想要的。

    phone = Field()
    class Meta:
        model = Phones
        # exclude = ('id', )
    def dehydrate_url(self,phone):

If you need to get hold of the file data before import, it is easy, just use the before_import() method:如果您需要在导入之前获取文件数据,这很容易,只需使用before_import()方法:

This needs to be declared in your Resource, for example:这需要在您的资源中声明,例如:

class BookResource(resources.ModelResource):

    def before_import(self, dataset, using_transactions, dry_run, **kwargs):
        for row in dataset.dict:
            print(row)

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

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