Python Django xadmin 可以对数据进行简单的逻辑处理嘛?
怪我咯
怪我咯 2017-04-18 10:30:18
0
3
683

各路大神,我想请教下django xadmin是否可以对数据进行简单的逻辑运算?如果有的话请详细告知下如何进行编写,多谢了!


以上图为例,我想知道图中的“可消费金额”是否可以通过“充值金额”加上基础金额(这里大家可以默认为100的定值)运算得出,日后后台的管理人员只需要录入“充值金额”就可以自动计算出“可消费金额”这个字段,并保存存入数据库

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
PHPzhong

This requirement is relatively easy to meet, just add a custom field to your Admin class.
The Admin class for your recharge record is as follows, assuming that the consumable amount field for price adjustment is consumable_account:

class ChargeRecordAdmin(object):
    list_display = ('card_no', 'name', 'charge_amount', 'consumable_amount')

    def consumable_amount(self, instance):
        return instance.charge_amount + 100

    consumable_amount.short_description = '可消费金额'
    consumable_amount.is_column = True
    consumable_amount.allow_tags = True

This added consumable_amount can be used like other fields, such as layout, etc.

阿神

According to what you said

Managers only need to enter the "recharge amount" to automatically calculate the "consumable amount"

Can I understand that the recharge amount on the page is a fillable field, and when the administrator enters the corresponding value, the subsequent consumable amount is immediately generated? If this is the case, it can be solved using js in the page.

As for the logical processing of data, do you want to do it before the page is generated or after the page is generated? Is the so-called data here retrieved from the database in the background or entered on the page?
The description of the problem is a bit vague.

大家讲道理

@agnewee Thank you very much for your answer
Maybe the description of my problem is not very clear, so I would like to make a supplement. The framework I use is Django, and the question refers to Django’s xadmin (which can also be understood as admin, but xadmin is (rewritten it)) Whether it can perform logical processing on the page? Because Django's admin is the background management page that comes with the framework, I am a little confused because I don't know how to write logical processing for its View and process the logic. The results are returned to the Html page

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template