I'm running a Django installation with geoDjango, and have created a model like this:
#models.py from django.contrib.gis.db import models class Route(models.Model): name = models.CharField(max_length=100) path = models.LineStringField(srid=4326) objects = models.GeoManager() def __unicode__(self): return str(self.path)
This worked, and I was able to create linestring objects, within terminal, and admittedly I never got them to really show, but that was more with my displaying not being fully finished yet.
But then I saw a screencast, although from 2008, with the geodjango creator - bronn, where he got an openlayer open street map inteface on the admin page, and I followed his instructions adding an admin.py with an OSMGeoAdmin ending up like this:
#admin.py from django.contrib.gis import admin from myproject.georoute.models import Route class RouteAdmin(admin.OSMGeoAdmin): search_fields = ('name',) admin.site.register(Route, RouteAdmin)
This is also working fine - I get a map on which I can draw a linestring, but when i try to save it - or if I have a Route object already created and try to view the Route list on adminpage - I get an error. More specifically "coercing to Unicode: need string or buffer, LineString found" and from what I understand this comes from trying to unicode a object that doesn't have a __ unicode__ function(or something like this).
So I checked the linestring object definition and there was no unicode function so I did a feeble attempt of adding one, with no luck.
So here I am, stumped. Anyone knows how I may solve this problem?
edit stacktrace:
Environment: Request Method: POST Request URL: http://storm.webfactional.com/admin/georoute/route/add/ Django Version: 1.2.1 Python Version: 2.6.5 Installed Applications: ['django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.sites', 'django.contrib.messages', 'django.contrib.gis', 'django.contrib.admin', 'registration', 'georoute'] 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 "/home/storm/webapps/django/lib/python2.6/django/core/handlers/base.py" in get_response 100. response = callback(request, *callback_args, **callback_kwargs) File "/home/storm/webapps/django/lib/python2.6/django/contrib/admin/options.py" in wrapper 239. return self.admin_site.admin_view(view)(*args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/views/decorators/cache.py" in _wrapped_view_func 69. response = view_func(request, *args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/contrib/admin/sites.py" in inner 190. return view(request, *args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/utils/decorators.py" in _wrapper 21. return decorator(bound_func)(*args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/utils/decorators.py" in _wrapped_view 76. response = view_func(request, *args, **kwargs) File "/home/storm/webapps/django/lib/python2.6/django/utils/decorators.py" in bound_func 17. return func(self, *args2, **kwargs2) File "/home/storm/webapps/django/lib/python2.6/django/db/transaction.py" in _commit_on_success 299. res = func(*args, **kw) File "/home/storm/webapps/django/lib/python2.6/django/contrib/admin/options.py" in add_view 800. self.log_addition(request, new_object) File "/home/storm/webapps/django/lib/python2.6/django/contrib/admin/options.py" in log_addition 428. object_repr = force_unicode(object), File "/home/storm/webapps/django/lib/python2.6/django/utils/encoding.py" in force_unicode 66. s = unicode(s) Exception Type: TypeError at /admin/georoute/route/add/ Exception Value: coercing to Unicode: need string or buffer, LineString found