Example:
class StatsInline(admin.TabularInline): model = Stats fields = ('clicked', 'shown', 'avg') readonly_fields = ('avg',) verbose_name = 'Stats' verbose_name_plural = 'Stats' can_delete = False def avg(self, obj): return float(obj.clicked) / obj.shown if obj.shown else 0
P.S. float conversion is needed to avoid casting result to int (e.g. 1/2=0, float(1)/2=0.5)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.