-
Notifications
You must be signed in to change notification settings - Fork 248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
AttributeError: 'int' object has no attribute 'isnumeric' #117
Comments
I suggest something like the following patch to fix this: Index: django-ajax-selects/ajax_select/fields.py
===================================================================
--- django-ajax-selects.orig/ajax_select/fields.py 2015-04-07 01:41:13.000000000 +1000
+++ django-ajax-selects/ajax_select/fields.py 2015-04-10 13:19:52.290799463 +1000
@@ -26,6 +26,10 @@
def _as_pk(got):
# a unicode method that checks for integers
+ if isinstance(got, int):
+ return got
+ if IS_PYTHON2 and isinstance(got, long):
+ return got
if got.isnumeric():
if IS_PYTHON2:
return long(got) |
isnumeric is a method of Unicode. So we should check that first. I've gotten unit tests and Travis, Tox set up so soon these pull requests
|
basic travis and tox are now added. I will implement tests when I get a I think that maybe your test (the one that showed this error) is supplying in any case the correct way is to get the model field and use its https://docs.djangoproject.com/en/1.8/howto/custom-model-fields/#converting-values-to-python-objects but I don't see any reason why the form field or widget should be doing On Fri, Apr 10, 2015 at 8:16 AM felix crucialfelix@gmail.com wrote:
|
Thanks for your prompt fix. Yes, I was wondering about my code too. I couldn't see the problem yesterday. Oh wait, I see the issue now, will fix it. |
isnumeric() works in Python 3. It does not seem to work in Python2. |
It's a method of unicode, but not of str: >>> u"2".isnumeric()
True
>>> "2".isnumeric()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'isnumeric' |
Hello,
If the value to _as_pk is already int, _as_pk fails:
The text was updated successfully, but these errors were encountered: