Wednesday, July 29, 2020

Admin list sorting problem

-----BEGIN PGP SIGNATURE-----

iQEzBAEBCAAdFiEE/NCg7Xf1UydoVFgpGvW31BqCOLMFAl8ibX8ACgkQGvW31BqC
OLOIQQf/RY2scBtG3OnQMpBuuEW+VwqDI5hcNoPLp7d/EhnJKba8cMfDqvtsuQiI
XdkEpAd17EF0eKGsCmSBLxiKCGXI1576f4uapsv0XtAsg5RXc+ipc5CZDaVwYhrp
V9/iu3o86yRJdssyBrUy//2EIYpdJlSvTQroBvkRZALIx3jiKXysBlk8juBpKs5p
iW1NcEc1JA/bj3Cybf/zRPOSFsjIlmDtuStPRUVTuSHW58g49O3E3NARdsWexTUL
sx+tHHxjepJVzuU4vAAGbJ1r3vxiVpN3L0rk7iqnMSwK+amEJkRHDvO7ogNcGrEh
Szg+clzDoWhKcHcFw74Pf+mriFQ6Zg==
=evFW
-----END PGP SIGNATURE-----
I have looked closely at the Admin docs and the page source and I think
I'm at the blank wall.

I have a collection of 14,000+ chemical names which just naturally sort
weirdly. This is because scientists insist on incuding "locants" in
chemical names. Locants indicate where sub-molecules sit in the actual
whole molecule. That isn't a sufficiently scientific description but
with the following example should suffice to decribe my problem.

2,4-Toluene diisocyanate
2,4,6-tris(dimethylaminomethyl)phenol
2,6-Toluene diisocyanate

Django wants to sort this alphanumerically but scientists don't want to
see it that way.

I wrote a chemsort algorithm and added a sort field (slug) to the model
and used the model's Meta class ordering to sort the chemical according
to slug.

2,4,6-tris(dimethylaminomethyl)phenol----->>
dimethylaminomethylphenol246tris
... (many thousands more chemicals) ...
2,4-Toluene diisocyanate----->> toluenediisocyanate24
2,6-Toluene diisocyanate ----->> toluenediisocyanate26

This works fine until in the Admin, on clicking the substance name in
the heading everything reverts to sorting on the name instead of the slug.

This is understandable because, sensibly, the Admin appears to use
javascript to handle such resorting in the browser instead of making a
round trip to the database via the server. Therefore, I think I need
slug in the list for an in-browser solution.

I would like to include the slug in the Admin but severely reduce the
allocated real-estate to just one or two characters.

How can I do that? Maybe there is another solution?

Thanks

Mike


--
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/a21aa10e-1049-7263-f4e3-adcd742062c8%40dewhirst.com.au.

No comments:

Post a Comment