2

I am using Django-import_export for exporting data. I have used the code given below that's not working correctly. It exported only dehydrated data instead of given fields.

class MemberResource(resources.ModelResource):
    Brand=Field()
    class meta:
        model = model
        fields=('title','Brand')
    def dehydrate_Brand(self, obj):
        return str(obj.Brand.title)

class modelAdmin(ImportExportModelAdmin):
    resource_class = MemberResource
    list_display=['title','Model_code','Chipset','chipset_description','Brand','categories']
    search_fields = ['title','Model_code','Chipset',]
    fields=('title','Model_code','Chipset','chipset_description','image','Brand','Cat')
admin.site.register(model,modelAdmin)
1
  • 1
    rename meta to Meta. Commented Jul 17, 2022 at 12:56

1 Answer 1

2

The name of the Meta subclass is Meta, not meta, so the ModelResource should look like:

class MemberResource(resources.ModelResource):
    Brand=Field()
    
    class Meta:
        model = Member
        fields = ('title','Brand')
    
    def dehydrate_Brand(self, obj):
        return str(obj.Brand.title)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.