Django import-export choices field

前端 未结 2 1260
栀梦
栀梦 2021-01-20 15:06

I have a model with choices list (models.py):

class Product(models.Model):
    ...
    UNITS_L = 1
    UNITS_SL = 2
    UNITS_XL = 3
    PRODUCT         


        
2条回答
  •  耶瑟儿~
    2021-01-20 15:26

    You can use 'get_FOO_display' to achieve this in the Django Admin:

    class ProductReportResource(resources.ModelResource):
        product_size = fields.Field(
            attribute='get_product_size_display',
            column_name=_(u'Product Size')
        )
    

提交回复
热议问题