In the Admin I want the user to be able to enter a decimal number with a
percentage sign (eg 33.3%) or without (eg 33.3) and to collect it as a
decimal number.
At the moment DecimalField barfs if the user enters a human style
percentage sign.
My initial thought is to change it to a CharField and muck around making
an awful mess behind the scenes to get - and store - the 0 to 100
decimal value I really want.
On the other hand, there is a snippet ...
https://djangosnippets.org/snippets/1914/
... which looks promising but I'm not sure how to get that into the Admin
I have seen Django Extras has a PercentField but that seems to be a lot
of stuff to solve a small "simple" problem. Also, I haven't seen where
to slip it into the Admin
There is a ticket #17662 (now closed 'wontfix') but that focuses on
doing conversions which isn't what I'm after.
Here is another approach based on the snippet quoted above ...
http://stackoverflow.com/questions/6690692/problem-rendering-a-django-form-field-with-different-representation
... and which draws a suggestion to use a MultiValueField. I didn't try
too hard to understand the Django docs on MultiValueField because if
that is the answer I'm trying to fix the wrong problem.
I just want to ignore the percent sign if the user sticks it into a
DecimalField.
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-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/554FFB68.5050804%40dewhirst.com.au.
For more options, visit https://groups.google.com/d/optout.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment