我已经安装了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)我想填充位置字段中的所有城市,如果可能的话,使用自动完成功能。
发布于 2018-07-16 10:14:00
在installation和填充表之后,
python manage.py cities_light将city定义为外键。
from cities_light.models import City
class UserProfile(models.Model):
    city = models.ForeignKey(City)要查看City对象,请打开一个shell会话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.longitudehttps://stackoverflow.com/questions/41877111
复制相似问题