python - Getting HTML to linebreak in django admin's display -


i have django display

the code doing is:

class purchaseorder(models.model):     product = models.manytomanyfield('product', null =true)      def get_products(self):         return "\n".join([p.products p in self.product.all()])  class product(models.model):     products = models.charfield(max_length=256, null =true)      def __unicode__(self):          return self.products 

views.py:

class purchaseorderadmin(admin.modeladmin):    fields = ['product']    list_display = ('get_products') 

so i've attempted this:

from django.utils.html import format_html   def get_products(self):     return format_html(" <p> </p>").join([p.products p in self.product.all()]) 

however, it's still not returning in html. or rather, way want in image

you need set field allow tags html show in admin list display:

class purchaseorder(models.model):     product = models.manytomanyfield('product', null =true)      def get_products(self):         return "<br />".join([p.products p in self.product.all()])     get_products.allow_tags = true 

see the docs more information.


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -