Opened 15 years ago
Closed 15 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: | no | UI/UX: | no |
Description (last modified by )
When you start the shell (python manage.py shell) and paste the following code (pasted from http://docs.djangoproject.com/en/dev/ref/contrib/gis/model-api/):
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 by , 15 years ago
| Description: | modified (diff) |
|---|
comment:2 by , 15 years ago
I tested this on Python 2.6.1 and there it also causes the same problem. And line 49 refers to base.py
comment:3 by , 15 years ago
| Component: | Contrib apps → GIS |
|---|
comment:4 by , 15 years ago
| Resolution: | → invalid |
|---|---|
| Status: | new → closed |
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.
Fixed up the formatting.