On 6/02/2018 10:27 PM, Julio Biason wrote:
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.
Agreed. This is what I have done to date ...
In substance.save() ...
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
<mailto: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+unsubscr...@googlegroups.com
<mailto:django-users%2bunsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@googlegroups.com>.
Visit this group at https://groups.google.com/group/django-users
<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
<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
<https://groups.google.com/d/optout>.
--
*Julio Biason*,Sofware Engineer
*AZION* | Deliver. Accelerate. Protect.
Office: +55 51 3083 8101 <callto:+555130838101> | Mobile: +55 51
<callto:+5551996209291>_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+unsubscr...@googlegroups.com
<mailto:django-users+unsubscr...@googlegroups.com>.
To post to this group, send email to django-users@googlegroups.com
<mailto:django-users@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
<https://groups.google.com/d/msgid/django-users/CAEM7gE1%3DDRwnaOjJhf63EPXzjKGv083M-NNwCN7%2BfhbgeZRz-Q%40mail.gmail.com?utm_medium=email&utm_source=footer>.
For more options, visit https://groups.google.com/d/optout.
--
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 post to this group, send email to django-users@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/358d35a3-86d6-52e0-2c34-7382b73b7342%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.