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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4160ee4d-8b36-1118-1bec-2ba8ab40d891%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Hi Mike,One thing that occurs me is that you can override the model save() to update another field -- one that the user doesn't have access. On that function, you will write a new field, say `sortable_name` in which you'll transfor the chemical name into something that will appear in the proper order, like converting alphas to A, betas to B, etc.
self.slug = greek_tweak(self.name, allow_unicode=True)substance.slug is not displayed anywhere and nor is it used in urls because there can be many substances with the same name. And greek_tweak() ...
def greek_tweak(name, allow_unicode=True): name = name.replace('α', 'a').replace('β', 'b').replace('γ', 'g') name = name.replace('δ', 'd').replace('ε', 'e') return slugify(name, allow_unicode)And back in substance Meta ...
ordering = ['slug']
When you request the list of chemicals by name order, you actually use the `sortable_name` field, which will have all the conversions in place.
--
On Mon, Feb 5, 2018 at 9:55 PM, Mike Dewhirst <mi...@dewhirst.com.au> wrote:
Chemical names start with both upper and lower case as well as Greek characters. Chemical names also exist in multiple non-western non-latin languages.
To get lists of chemicals sorting more or less "correctly" I currently slugify with allow_unicode=True.
This for example gets tert-Butyl... sorted nicely among names starting with upper-case T.
Unfortunately the α-terpineol or beta this or ε that all sink to the end of the list instead of sorting into the A, B or Es.
My google-fu indicates I can sort on a property but that is slow. I have thought about tweaking slugify to include a table of equivalences between Greek and Western chars but that doesn't necessarily cater for non-Western character sets. Maybe an ever expanding table of equivalences?
Thanks for any ideas ...
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 post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/4160ee4d-8b36-1118-1bec-2ba8ab40d891%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
--
Julio Biason, Sofware Engineer
AZION | Deliver. Accelerate. Protect.Office: +55 51 3083 8101 | Mobile: +55 51 99907 0554
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAEM7gE1%3DDRwnaOjJhf63EPXzjKGv083M-NNwCN7%2BfhbgeZRz-Q%40mail.gmail.com.
--
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...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/bfd1633b-a651-fec9-6f2a-86efac8d2e8c%40dewhirst.com.au.