Django-profiles,带有地理字段的用户配置文件?

发布于 2024-12-15 15:03:11 字数 714 浏览 5 评论 0原文

我第一次使用 django-profiles ,所以我可能会错过一些基本的东西。

我想创建一个包含地理字段的 UserProfile 模型。具体来说,是这样的:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phone = PhoneNumberField()
    address = models.CharField(max_length=200)
    distance = models.IntegerField()
    zone = models.ForeignKey(Hood, null=True, blank=True)
    location = models.PointField(srid=900913, null=True, blank=True)
    objects = models.GeoManager()

我从 contrib.gis.db 导入模型,并从 auth 导入通用用户模型。

当我尝试运行syncdb时,出现以下错误:

AttributeError: 'module' object has no attribute 'PointField'

I am working with django-profiles for the first time, so I might be missing something basic.

I'd like to create a UserProfile model that includes geographic fields. Specifically something along these lines:

class UserProfile(models.Model):
    user = models.OneToOneField(User)
    phone = PhoneNumberField()
    address = models.CharField(max_length=200)
    distance = models.IntegerField()
    zone = models.ForeignKey(Hood, null=True, blank=True)
    location = models.PointField(srid=900913, null=True, blank=True)
    objects = models.GeoManager()

I'm importing models from contrib.gis.db, and also importing the generic User model from auth.

when I try to run syncdb, I get the following error:

AttributeError: 'module' object has no attribute 'PointField'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅浅 2024-12-22 15:03:11

您应该将此行添加到 models.py 中,并且之后不要将任何内容导入为模型。

从 django.contrib.gis.db 导入模型

you should add this line to models.py and don't import anything as models after that.

from django.contrib.gis.db import models

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文