Opened 8 years ago

Closed 8 years ago

#13715 closed (invalid)

Creating GeoDjango model in shell does not work

Reported by: drdee Owned by: nobody
Component: GIS Version: 1.2
Severity: Keywords: geodjango, postgresql 8.4, postgis 1.5
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description (last modified by Alex Gaynor)

When you start the shell (python shell) and paste the following code (pasted from

from django.contrib.gis.db import models

class Zipcode(models.Model):
    code = models.CharField(max_length=5)
    poly = models.PolygonField()
    objects = models.GeoManager()

then you receive the following error 'list index out of range'

line 49: kwargs = {"app_label": model_module.__name__.split('.')[-2]}

the model_module refers to: <module '__main__' from '/Library/Python/2.5/site-packages/IPython/FakeModule.pyc'>

This happens with Postgresql 8.4, postgis 1.5.1, OSX 10.5, python 2.5.2

Change History (4)

comment:1 Changed 8 years ago by Alex Gaynor

Description: modified (diff)

Fixed up the formatting.

comment:2 Changed 8 years ago by drdee

I tested this on Python 2.6.1 and there it also causes the same problem. And line 49 refers to

comment:3 Changed 8 years ago by Russell Keith-Magee

Component: Contrib appsGIS

comment:4 Changed 8 years ago by jbronn

Resolution: invalid
Status: newclosed

This is not an issue specific to GeoDjango -- same results when the import is from django.db import models and there's no PolygonField or GeoManager. Declaring Django models like this at the shell is not the proper way to define models, as they expect to be a part of an application namespace (hence why it's barfing when trying to figure out the app_label).

If what you really want are dynamic models, then I suggest checking out the existing materials on the subject.

Note: See TracTickets for help on using tickets.
Back to Top