-----BEGIN PGP SIGNATURE-----
iQEzBAEBCAAdFiEE/NCg7Xf1UydoVFgpGvW31BqCOLMFAl8j0AgACgkQGvW31BqC
OLNMDAgAqFvfKY1KD9elLdmwmr9AuDaGcaWZ3gDK18WZzAZ9ahH3O7D1rEwce20z
WkpSvjAcMbF991HAD/lZDoFalqQ8p/PjlHM7kJOVF1ZrmGh6PMcxj2wytlN2JeML
rkrjPjdtwJqnmsw9CdvJyc2ZiJhj6jSw+cWTb7tgNbuyoQikVh+yd1fadEigrXQI
d/j8ovwZyaAbbmRFWBKveoHTra/IuN3xgLyPWr6UjHdDlznsZF9YsgE+HiX5WlIS
PXAE/J7X+X0AKdHgvtlMK1bWsoPUnn2FixHf1CQNEmwxbnWAWehHmVnOCiA54san
3eH9Xi1DuCEObuyqlJ31RSVesYHakA==
=qMcU
-----END PGP SIGNATURE-----
On 31/07/2020 4:24 pm, Derek wrote:
> Apologies for lack of proof reading; the example code should be:
>
>
> def _name(self, obj):
> return '%s' % obj.name
> _name.admin_order_field = 'sort_name'
>
>
> On Friday, 31 July 2020 08:21:45 UTC+2, Derek wrote:
>
> I've had to do something similar to handle species.
>
Brilliant!
Thanks Derek
>
> I'd suggest breaking "pure" database design and creating a new
> field - say, "sort_name". This is created "on save" (obviously
> you can run a script to quickly generate this field's values for
> all existing records). You don't show "sort_name" on the admin
> interface; what you then do is create a new attribute on the
> chemical model - call it "_name"; this displays the actual
> chemical name, but the sort is set to your new field. Something
> like:
>
> def _name(self):
> return '%s' % self.name <http://self.name>
> _name.admin_order_field = 'display_name'
>
> In the Admin, only show "_name" and not "sort_name" or "name".
>
> HTH
> Derek
>
> On Thursday, 30 July 2020 08:51:01 UTC+2, Mike Dewhirst wrote:
>
> 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
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/4fc11cfc-4dec-45e7-aa19-768e7c5b2a9fo%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/4fc11cfc-4dec-45e7-aa19-768e7c5b2a9fo%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
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/906b8923-facb-7f3c-d72a-24db7fd2c1d3%40dewhirst.com.au.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment