5👍
✅
You can do it in a couple of ways:
Add a custom property in PurchaseOrder
class PurchaseOrder(models.Model):
price = models.FloatField()
@property
def dollar_amount(self):
return "$%s" % self.price if self.price else ""
and reference dollar_amount
instead of price
Another way
Add it in the PurchaseOrderAdmin
class PurchaseOrderAdmin(admin.ModelAdmin):
fields = ['product', 'price', 'purchase_date', 'confirmed']
list_display = ('product', 'dollar_amount', 'purchase_date', 'confirmed', 'po_number')
def dollar_amount(self, obj):
return "$%s" % obj.price if obj.price else ""
admin.site.register(PurchaseOrder, PurchaseOrderAdmin)
I would personally prefer option 1 so that we could reuse the code if the same has to be done with the actual app.
Source:stackexchange.com