0

我想解决这个错误并完成测试:

管理员.py

def suit_row_attributes(self, obj, request):
    """Add colours to the rows according to the status"""

    type_error = 'notSent'
    status_colours = {Transaction.STATUS_REJECTED: 'error', Transaction.STATUS_RECEIVED: 'received',
                      Transaction.STATUS_PENDING: 'warning', Transaction.STATUS_ACCEPTED: 'success',
                      type_error: 'notSent'}
    try:
        tt_status = Transaction.objects.get(txid=obj.numero).last_status
    except Transaction.DoesNotExist:
        tt_status = type_error
    return {'class': status_colours.get(tt_status, 'success')}

在测试.py

def test_suit_row_attributes(self):
    self.assertEqual(self.admin_instance.suit_row_attributes(self.errortr_obj), {'class': 'notSent'})

有人能帮助我吗?

4

1 回答 1

0
from django.contrib.admin import ModelAdmin

class CountryAdmin(ModelAdmin):
    ...

    def suit_row_attributes(self, obj, request):
        return {'class': 'type-%s' % obj.type}

    # Or bit more advanced example
    def suit_row_attributes(self, obj, request):
        css_class = {
            1: 'success',
            0: 'warning',
            -1: 'error',
        }.get(obj.status)
        if css_class:
            return {'class': css_class, 'data': obj.name}

更多信息:- https://django-suit.readthedocs.io/en/develop/list_attributes.html

于 2022-02-11T06:19:43.850 回答