1

I'm trying to debug this issue, but none of the existing answers help. When I run the Django server, I'm seeing:

'module' object has no attribute 'OSMGeoAdmin'

I'm aware this question is the same error, but django.contrib.gis.admin imports correctly and I'm developing on a Mac, not Windows. I have gdal installed, along with geos. I've run this app several times and have not seen the error before. GDAL is installed and configured correctly, with paths set correctly. Geos is installed. I've cleared out my virtual env, started over, and reinstalled, to no avail.

Frustratingly, I was able to get the app to run correctly, until I started troubleshooting an issue with sorl-thumbnail. Looking at my bash history, I did try to install jpegsrc (along with PIL as pip install PIL --allow-unverified PIL --allow-all-external) like this:

curl -O http://www.ijg.org/files/jpegsrc.v8c.tar.gz
tar zxvf jpegsrc.v8c.tar.gz
cd jpeg-8c/
./configure
make
sudo make install

Thank you for any help you are able to provide.

Full Traceback:

    Request Method: GET
    Request URL: http://0.0.0.0:8003/

    Django Version: 1.5.4
    Python Version: 2.7.5
    Installed Applications:
    ('django.contrib.auth',
     'django.contrib.contenttypes',
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages',
     'grappelli',
     'django.contrib.admin',
     'django.contrib.markup',
     'django.contrib.humanize',
     'django.contrib.gis',
     'south',
     'parks',
     'sorl.thumbnail')
    Installed Middleware:
    ('django.middleware.common.CommonMiddleware',
     'django.contrib.sessions.middleware.SessionMiddleware',
     'django.middleware.csrf.CsrfViewMiddleware',
     'django.contrib.auth.middleware.AuthenticationMiddleware',
     'django.contrib.messages.middleware.MessageMiddleware')


    Traceback:
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response
      103.                     resolver_match = resolver.resolve(request.path_info)
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in resolve
      319.             for pattern in self.url_patterns:
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in url_patterns
      347.         patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/core/urlresolvers.py" in urlconf_module
      342.             self._urlconf_module = import_module(self.urlconf_name)
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
      35.     __import__(name)
    File "/Volumes/public/DataServices/Code/Django/BostonGreen/bostongreenmap/bostongreenmap/urls.py" in <module>
      9. admin.autodiscover()
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/contrib/admin/__init__.py" in autodiscover
      29.             import_module('%s.admin' % app)
    File "/Users/mapcuser/.venvs/bostongreenmap/lib/python2.7/site-packages/django/utils/importlib.py" in import_module
      35.     __import__(name)
    File "/Volumes/public/DataServices/Code/Django/BostonGreen/bostongreenmap/parks/admin.py" in <module>
      13. class ParkAdmin(admin.OSMGeoAdmin):

    Exception Type: AttributeError at /
    Exception Value: 'module' object has no attribute 'OSMGeoAdmin'

admin.py:

            from django.contrib.gis import admin

            from parks.models import Facility, Neighborhood, Park, Activity, Event, Parktype, Parkowner, Parkimage, Facilitytype, Friendsgroup, Story
            from sorl.thumbnail import default
            from django.conf import settings

            # default GeoAdmin overloads
            admin.GeoModelAdmin.default_lon = -7912100
            admin.GeoModelAdmin.default_lat = 5210000
            admin.GeoModelAdmin.default_zoom = 11


            class ParkAdmin(admin.OSMGeoAdmin):
                list_display = ['name', 'parkowner' ]
                list_filter = ('neighborhoods', )
                search_fields = ['name']
                exclude = ('slug', )

                def park_image_thumb(self, obj):
                     if obj.image:
                         thumb = default.backend.get_thumbnail(obj.image.file, settings.ADMIN_THUMBS_SIZE)
                         return u'<img width="%s" src="%s" />' % (thumb.width, thumb.url)
                     else:
                         return "No Image" 
                park_image_thumb.short_description = 'Park Image'
                park_image_thumb.allow_tags = True

                readonly_fields = ['park_image_thumb',]



            class FacilityAdmin(admin.OSMGeoAdmin):
                search_fields = ['name', 'park__name']
                exclude = ('park',)
                list_display = ['pk', 'name', 'activity_string', 'facilitytype', ]
                list_editable = ['name', 'facilitytype', ]
                list_filter = ('activity', )


            class LookupAdmin(admin.ModelAdmin):

                def ic(self, obj):
                    if hasattr(obj, 'icon'):
                        thumb = default.backend.get_thumbnail(obj.icon.file,"24")
                        return u'<img width="%s" src="%s" />' % (thumb.width, thumb.url)
                    else:
                        return ""

                ic.short_description = 'Park Image'
                ic.allow_tags = True

                list_display = ['id', 'name','ic' ]
                list_editable = ['name', ]


            class ParkimageAdmin(admin.ModelAdmin):
                list_display = ['pk', 'thumbnail', 'caption', 'get_parks_string' ]
                list_editable = ['caption', ]
                search_fields = ['caption', ]
                readonly_fields = ('thumbnail',)
                list_per_page = 20


            #admin.site.register(Greenspace, admin.OSMGeoAdmin)
            admin.site.register(Facility, FacilityAdmin)
            admin.site.register(Facilitytype, LookupAdmin)
            admin.site.register(Park, ParkAdmin)
            admin.site.register(Parktype, LookupAdmin)
            admin.site.register(Parkowner, LookupAdmin)
            admin.site.register(Parkimage, ParkimageAdmin)
            admin.site.register(Neighborhood, admin.OSMGeoAdmin)
            admin.site.register(Activity, LookupAdmin)
            admin.site.register(Event)
            admin.site.register(Friendsgroup)
            admin.site.register(Story)
Community
  • 1
  • 1
allthesignals
  • 307
  • 2
  • 13

2 Answers2

0

You need to specify the class attribute overloads in each subclass like this:

class FacilityAdmin(admin.OSMGeoAdmin):
    default_lon = -7912100
    default_lat = 5210000
    default_zoom = 11

    search_fields = ['name', 'park__name']
    exclude = ('park',)
    list_display = ['pk', 'name', 'activity_string', 'facilitytype', ]
    list_editable = ['name', 'facilitytype', ]
    list_filter = ('activity', )
garnertb
  • 9,454
  • 36
  • 38
0

this error : 'module' object has no attribute 'OSMGeoAdmin'

came form admin.py

only add .gis like that:

from django.contrib.gis import admin

guest_man
  • 1
  • 1