Tuesday, June 1, 2021

Re: SVG widget for the Admin

You haven't defined where in the admin interface you want this image to be displayed?  A table?

I have not tried this, but could you not create an additional field on your model that returns the HTML-encoding needed to display the SVG?

E.g. 

class MyModel():
    svg_text = CharField()

    def _the_svg(self):
        return """<svg width="100" height="100">%s</svg>""" % self.svg_text
        _the_svg.allow_tags = True
        
I am not sure about editing visually, however - I would expect that would require a specialised widget.

HTH
Derek


On Tuesday, 1 June 2021 at 03:28:59 UTC+2 Mike Dewhirst wrote:
I collect the svg source for an image from a public API and store it in
a models.TextField. I have no difficulty displaying it in a normal view
and my own template. Nothing special, it just emerges. I don't even need
a 'safe' filter.

However, I really want to display such images in the Admin. At this
stage all it displays is the svg source.

What is the correct way to make the image appear in the Admin?

Do I need a special field inheriting from TextField? Do I need a special
widget? Is there a way to mark admin field values as safe?

Thanks for any hints

Mike

--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/520bf296-ec68-48ad-8fe2-f106823efac2n%40googlegroups.com.

No comments:

Post a Comment