Экспортировать только столбцы list_display с именами verbose_name?

Здравствуйте, я новичок в django, поэтому у меня есть основной вопрос. В своем классе администратора я добавил ExportMixin и хочу сохранить excel файл с моими столбцами list_display и названиями verbose. Не id colum или, скажем, у меня есть статус, он говорит продолжать или не делать, но я показываю 0 -1 под статусом.

Я все еще ищу ответ, пожалуйста, помогите мне :)

MyCode:

@admin.register(Ico)
class IcoAdmin(ExportMixin, BaseAdmin):
    list_display = (
        'account', 'pair', 'amount', 'ico_situation', 'expire_date', 'price',
        'token_amount', 'reference_user', 'get_reference_user_income')
    list_filter = ('account', 'account__is_bot')
    search_fields = ('account_id', 'wallet_id', 'ico_situation')

    raw_id_fields = ('account', 'pair', 'wallet', 'reference_user')

Моя таблица Excel :

id account кошелек пара сумма token_amount final_token_amount expire_date статус ico_situation price код_ссылки reference_user
152 111 789 12 100 400 0 2022-03-17 1 1 0,25
151 111 789 12 100 200 0 2021-11-17 1 0 0,5
150 111 789 12 100 200 0 2021-11-17 1 0 0,5 2
149 111 789 12 100 200 0 2021-11-17 1 0 0,5
148 111 789 12 100 200 0 2021-11-17 1 0 0,5 2
147 111 789 12 100 200 0 2021-11-17 1 0 0,5
146 111 789 12 100 200 0 2021-11-17 1 0 0,5 2

Таблица мне нужна: (https://ibb.co/8YpQ0S1)

Спасибо за помощь :)

Объявив Resource на классе Admin, вы можете контролировать, какие поля появляются в экспорте. Вы перечисляете поля, которые хотите экспортировать, в атрибуте fields Meta.

class IcoResource(ModelResource):

    class Meta:
        model = Ico
        fields = (
            'account', 'pair', 'amount', 'ico_situation', 'expire_date', 'price',
            'token_amount', 'reference_user', 'get_reference_user_income'
        )
        
        
@admin.register(Ico)
class IcoAdmin(ExportMixin, BaseAdmin):
    resource_class = IcoResource

    # ... your other fields here

Вы можете управлять тем, как экспортируются поля, используя widgets

Надеюсь, я правильно понял ваш вопрос.

Ребята, я нашел решение.

коды здесь: -страница администратора приложения примера

 class BookResource(ModelResource):
    published = Field(attribute='published', column_name='Basim Tarihi')
    yazaradi = Field(attribute='author__name', column_name='Yazar Adi')
    # ico_situation = Field(attribute='ico_situation', column_name='Ico Durumu')
    imported = Field(attribute='imported', column_name='Onemli MI')
    ico_situation = Field(attribute='ico_situation')

    class Meta:
        model = Book
        widgets = {
            'published': {'format': '%d.%m.%Y'},
        }

        fields = ('yazaradi', 'price', 'author_email', 'categories', 'published', 'imported', 'ico_situation')
        export_order = ('yazaradi', 'price', 'author_email', 'categories', 'published', 'imported', 'ico_situation')

    def for_delete(self, row, instance):
        return self.fields['name'].clean(row) == ''


class BookAdmin(ImportExportMixin, admin.ModelAdmin):
    list_display = ('name', 'author', 'added')
    list_filter = ['categories', 'author']
    resource_class = BookResource

вы можете переименовать колонки excel в классе ModelResource

Вернуться на верх