On 3/06/2021 4:00 pm, Derek wrote:
>
> E.g.
>
> class MyModel():
>     svg_text = CharField()

in my case it is ...

class Chemical(models.Model):
    ...
    ddstructure = models.TextField(
        null=True,
        blank=True,
        verbose_name="2D structure",
    )


The above is unchanged.

# admin
class ChemicalAdmin(admin.ModelAdmin):

    def _ddstructure(self, obj):
        return mark_safe(obj.ddstructure)
    ...
    fieldsets = (
        (
            None,
            {
                "fields": (
                    "ddstructure",        # displays svg code
                    "_ddstructure",
                    ...
            }
    ),

FYI it works perfectly as a column in the list display - but I don't need it there, rather in the page for the chemical.

This is what happens if it is included in the fieldsets "fields" roster.


 FieldError at /admin/chemical/chemical/17/change/

Unknown field(s) (_ddstructure) specified for Chemical. Check 
fields/fieldsets/exclude attributes of class ChemicalAdmin.

Request Method:         GET
Request URL:    http://localhost:8088/admin/chemical/chemical/17/change/
Django Version:         3.2.3
Exception Type:         FieldError
Exception Value:        

Unknown field(s) (_ddstructure) specified for Chemical. Check 
fields/fieldsets/exclude attributes of class ChemicalAdmin.

Exception Location: D:\Users\mike\envs\xxai\lib\site-packages\django\contrib\admin\options.py, line 712, in get_form
Python Executable:      D:\Users\mike\envs\xxai\Scripts\python.exe
Python Version:         3.8.3


Cheers

Mike


>
>     def _the_svg(self):
>         return """<svg width="100" height="100">%s</svg>""" %
> self.svg_text
>         _the_svg.allow_tags = True



--
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+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/2f167985-9e2e-fc27-15d1-fc153c6b0077%40dewhirst.com.au.

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to