Problem installing and using smart_selects

761 views
Skip to first unread message

Michael Ackary

unread,
Mar 1, 2015, 6:33:00 PM3/1/15
to django...@googlegroups.com

Smart Selects looked so simple and promising for chained selects (https://github.com/digi604/django-smart-selects).  However, no matter how I install it, it doesn't seem to work.  Here is what I've tried:


Attempt #1 - putting it in django.contrib

Copied the smart_selects folder to /django/contrib/smart_selects

Added "django.contrib.smart_selects" to INSTALLED_APPS in settings.py

But within Django shell I got this error:

>>>  from django.contrib import smart_selects
>>>  smart_selects.urls
AttributeError: 'module' object has no attribute 'urls'



Attempt #2 - installed using pip

I removed the smart_selects folder from /django/contrib  folder (above) and then installed using pip... which put smart_selects in the Python site-packages folder.

But then trying to use smart_selects within urls.py produced an ugly "ImportError: cannot import name simplejson" which suggests smart_selects has some outdated dependencies. (I"m using Django 1.7).



Attemp #3 - putting smart_packages in the root folder of my Django project

When smart_selects is placed here, again I can import smart_selects from the Django shell  but not access smart-selects.urls :

Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> import smart_selects
>>> dir(smart_selects)
['__builtins__', '__doc__', '__file__', '__name__', '__package__', '__path__', 'models']
>>> smart_selects.urls
Traceback (most recent call last):
  File "<console>", line 1, in <module>
AttributeError: 'module' object has no attribute 'urls'


Finally it works if i do this:

>>> import smart_selects.urls
>>> smart_selects.urls
<module 'smart_selects.urls' from '/Users/chas/Projects/switch/djangoroot/smart_selects/urls.pyc'>



However, I really don't like putting apps here since they clutter up my own development (and would rather keep 3rd party apps in django/contrib). 

What am I missing about the smart_selects ?
Thank you,

Mike,

Jorge Andrés Vergara Ebratt

unread,
Mar 1, 2015, 6:37:41 PM3/1/15
to django...@googlegroups.com

Check the git repo, the issues page, one of the issues (I think the 4th) says that in the tittle, Can not import simple json.

You basically have to install it with pip but from the git branch, because they haven't updated pypy yet


--
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 http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/1034ee57-88fc-417e-a9d6-b5787815ffb9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Carl Meyer

unread,
Mar 1, 2015, 9:01:52 PM3/1/15
to django...@googlegroups.com
Hi Michael,

On 03/01/2015 01:11 AM, Michael Ackary wrote:
> Smart Selects looked so simple and promising for chained selects
> (https://github.com/digi604/django-smart-selects). However, no matter
> how I install it, it doesn't seem to work. Here is what I've tried:
>
>
> *Attempt #1 - putting it in django.contrib
> *
> Copied the smart_selects folder to /django/contrib/smart_selects
>
> Added "django.contrib.smart_selects" to INSTALLED_APPS in settings.py
>
> But within Django shell I got this error:
>
>>>> from django.contrib import smart_selects
>>>> smart_selects.urls
> AttributeError: 'module' object has no attribute 'urls'

You don't ever want to do this. The "django.contrib" module is for
modules distributed with Django; it's not a place to add your own
additional code.

It also doesn't work, because smart_select expects to be able to import
itself as "smart_select", not as "django.contrib.smart_select."

> *Attempt #2 - installed using pip
> *
> I removed the smart_selects folder from /django/contrib folder (above)
> and then installed using pip... which put smart_selects in the Python
> site-packages folder.
>
> But then trying to use smart_selects within urls.py produced an ugly
> "ImportError: cannot import name simplejson" which suggests
> smart_selects has some outdated dependencies. (I"m using Django 1.7).

This is the right way to make use of third-party code. The problem here,
as you say, is just that smart_select has some outdated code. It's
actually been fixed in master, just not posted to PyPI yet, so you'll
need to install it directly from git, as mentioned in the fourth comment
here: https://github.com/digi604/django-smart-selects/issues/70

> *Attemp #3 - putting smart_packages in the root folder of my Django project
> *
> When smart_selects is placed here, again I can import smart_selects from
> the Django shell but not access smart-selects.urls :
>
> Type "help", "copyright", "credits" or "license" for more information.
> (InteractiveConsole)
>>>> import smart_selects
>>>> dir(smart_selects)
> ['__builtins__', '__doc__', '__file__', '__name__', '__package__',
> '__path__', 'models']
>>>> smart_selects.urls
> Traceback (most recent call last):
> File "<console>", line 1, in <module>
> AttributeError: 'module' object has no attribute 'urls'
>
>
> Finally it works if i do this:
>
>>>> import smart_selects.urls
>>>> smart_selects.urls
> <module 'smart_selects.urls' from
> '/Users/chas/Projects/switch/djangoroot/smart_selects/urls.pyc'>

The difference between the "doesn't work" and "works" versions here
doesn't have anything to do with how you've installed the code, it's
simply how submodule imports work in Python. Submodules are never
automatically imported unless you import them explicitly.

> However, I really don't like putting apps here since they clutter up my
> own development (and would rather keep 3rd party apps in django/contrib).

Yes, this installation technique will work fine, but it clutters things
up and makes it harder to upgrade in the future.

Carl

signature.asc
Reply all
Reply to author
Forward
0 new messages