You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
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.
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.
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?
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Django users
I've had to do something similar to handle species.
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:
> _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):