class - How to display $ (dollar signs) in Django Admin? -


how can make under price variable can automatically have display $? so, instead of having 999.99, display $999.99. doing in django admin.

here admin.py

from django.contrib import admin purchaseorders.models import purchaseorder   class purchaseorderadmin(admin.modeladmin):     fields = ['product', 'price', 'purchase_date', 'confirmed']     list_display = ('product', 'price', 'purchase_date', 'confirmed', 'po_number') admin.site.register(purchaseorder, purchaseorderadmin) 

and here bit models.py

from django.db import models import random  class purchaseorder(models.model):     price = models.floatfield() 

you can in couple of ways:

add 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 in 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 prefer option 1 reuse code if same has done actual app.


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -