GeoDjango tutorial error: Cannot resolve keyword 'mpoly' into field
GeoDjango tutorial error: Cannot resolve keyword 'mpoly' into field
我正在学习 geodjango 的官方教程。我正在使用:
- geos 3.6.2
- proj.datumgrid1.5
- 项目 4.9.1
- gdal 2.3.1
- django 2.0.7
- PostGIS 2.4
我开始使用
>>> from mapmaybe.models import WorldBorder
>>> WorldBorder.objects.filter(mpoly__contains=pnt_wkt)
它returns这个错误跟踪:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/query.py", line 836, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/query.py", line 854, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1253, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1277, in _add_q
split_subq=split_subq,
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1153, in build_filter
lookups, parts, reffed_expression = self.solve_lookup_type(arg)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1015, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1379, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'mpoly' into field. Choices are: area, fips, geom, id, iso2, iso3, lat, lon, name, pop2005, region, subregion, un
有什么想法吗?提前致谢
添加以下模型:
enter code here
这是一个由 ogrinspect 创建的自动生成的 Django 模型模块。
从 django.contrib.gis.db 导入模型
class WorldBorder(models.Model):
fips = models.CharField(max_length=2)
iso2 = models.CharField(max_length=2)
iso3 = models.CharField(max_length=3)
un = models.IntegerField()
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.BigIntegerField()
region = models.IntegerField()
subregion = models.IntegerField()
lon = models.FloatField()
lat = models.FloatField()
geom = models.MultiPolygonField(srid=4326)
# Auto-generated `LayerMapping` dictionary for WorldBorder model
worldborder_mapping = {
'fips': 'FIPS',
'iso2': 'ISO2',
'iso3': 'ISO3',
'un': 'UN',
'name': 'NAME',
'area': 'AREA',
'pop2005': 'POP2005',
'region': 'REGION',
'subregion': 'SUBREGION',
'lon': 'LON',
'lat': 'LAT',
'geom': 'MULTIPOLYGON',
}
您的模型没有某些字段(如 mpoly
)。在 GeoDjango 教程模型中看起来像这样https://docs.djangoproject.com/en/2.0/ref/contrib/gis/tutorial/#defining-a-geographic-model:
from django.contrib.gis.db import models
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField)
mpoly = models.MultiPolygonField()
# Returns the string representation of the model.
def __str__(self):
return self.name
我正在学习 geodjango 的官方教程。我正在使用:
- geos 3.6.2
- proj.datumgrid1.5
- 项目 4.9.1
- gdal 2.3.1
- django 2.0.7
- PostGIS 2.4
我开始使用
>>> from mapmaybe.models import WorldBorder
>>> WorldBorder.objects.filter(mpoly__contains=pnt_wkt)
它returns这个错误跟踪:
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/manager.py", line 82, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/query.py", line 836, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/query.py", line 854, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1253, in add_q
clause, _ = self._add_q(q_object, self.used_aliases)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1277, in _add_q
split_subq=split_subq,
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1153, in build_filter
lookups, parts, reffed_expression = self.solve_lookup_type(arg)
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1015, in solve_lookup_type
_, field, _, lookup_parts = self.names_to_path(lookup_splitted, self.get_meta())
File "/home/spencer/PycharmProjects/demo/venv/lib/python3.6/site-packages/django/db/models/sql/query.py", line 1379, in names_to_path
"Choices are: %s" % (name, ", ".join(available)))
django.core.exceptions.FieldError: Cannot resolve keyword 'mpoly' into field. Choices are: area, fips, geom, id, iso2, iso3, lat, lon, name, pop2005, region, subregion, un
有什么想法吗?提前致谢
添加以下模型:
enter code here
这是一个由 ogrinspect 创建的自动生成的 Django 模型模块。
从 django.contrib.gis.db 导入模型
class WorldBorder(models.Model):
fips = models.CharField(max_length=2)
iso2 = models.CharField(max_length=2)
iso3 = models.CharField(max_length=3)
un = models.IntegerField()
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.BigIntegerField()
region = models.IntegerField()
subregion = models.IntegerField()
lon = models.FloatField()
lat = models.FloatField()
geom = models.MultiPolygonField(srid=4326)
# Auto-generated `LayerMapping` dictionary for WorldBorder model
worldborder_mapping = {
'fips': 'FIPS',
'iso2': 'ISO2',
'iso3': 'ISO3',
'un': 'UN',
'name': 'NAME',
'area': 'AREA',
'pop2005': 'POP2005',
'region': 'REGION',
'subregion': 'SUBREGION',
'lon': 'LON',
'lat': 'LAT',
'geom': 'MULTIPOLYGON',
}
您的模型没有某些字段(如 mpoly
)。在 GeoDjango 教程模型中看起来像这样https://docs.djangoproject.com/en/2.0/ref/contrib/gis/tutorial/#defining-a-geographic-model:
from django.contrib.gis.db import models
class WorldBorder(models.Model):
# Regular Django fields corresponding to the attributes in the
# world borders shapefile.
name = models.CharField(max_length=50)
area = models.IntegerField()
pop2005 = models.IntegerField('Population 2005')
fips = models.CharField('FIPS Code', max_length=2)
iso2 = models.CharField('2 Digit ISO', max_length=2)
iso3 = models.CharField('3 Digit ISO', max_length=3)
un = models.IntegerField('United Nations Code')
region = models.IntegerField('Region Code')
subregion = models.IntegerField('Sub-Region Code')
lon = models.FloatField()
lat = models.FloatField()
# GeoDjango-specific: a geometry field (MultiPolygonField)
mpoly = models.MultiPolygonField()
# Returns the string representation of the model.
def __str__(self):
return self.name