在模板

时间:2017-01-26 15:35:47

标签: python django

我已经安装了Django city light。现在,我希望以django city light中的所有城市以登记形式填写我的城市场地。所有文件都没有提供有关如何做到这一点的任何指导。我的模特是:

class UserProfile(models.Model):
user = models.OneToOneField(User)
email = models.CharField(max_length=255, blank=True)
gender = models.CharField(max_length=16, blank=True)
location = models.CharField(max_length=255, blank=True)

我想填充位置字段中的所有城市,如果可能的话,还要填写自动完成功能。

1 个答案:

答案 0 :(得分:1)

installation之后并通过

填充表格
python manage.py cities_light

city定义为外键。

from cities_light.models import City

class UserProfile(models.Model):
    city = models.ForeignKey(City)

要查看City对象的样子,请打开外壳程序会话python manage.py shell并键入

from cities_light.models import City
c1 = City.objects.get(id=100)
dir(c1)

最相关的地理信息可能是

c1.name
c1.region
c1.country
c1.latitude
c1.longitude