已解决:灯具的 django pointfield 值格式

主要问题是无法为灯具指定自定义点场格式。

I am trying to load a fixture in Django that has a PointField. The value is stored in the database as:
<code>SRID=4326;POINT(1.23456789 1.23456789)
</code>
The fixture file looks like this:
<code>[{'model': 'myapp.MyModel', 'pk': 1, 'fields': {'point': SRID=4326;POINT(1.23456789 1.23456789)}},]
</code>
However, I get the following error when I try to load it: 
<blockquote>
<p>django.core.serializers.base.DeserializationError: Problem installing fixture '/path/to/fixture/file': Could not load myapp_mymodel(1): (point_field) invalid input syntax for type geometry</p>
</blockquote>


A:

 Django fixtures are in JSON format, so you need to use <code>"SRID=4326;POINT(1.23456789 1.23456789)"</code>.  Also, you need to use <code>"point"</code>, not <code>"Point"</code>.  This should work:  

    [{'model': 'myapp_mymodel', 'pk': 1, 'fields': {'point': "SRID=4326;POINT(1 23)"}}]

点文件

点文件是 Django 网络框架中用于存储网站信息的数据结构。 点文件包含有关单个网站的信息,例如 URL、域名和其他元数据。

Django 中的值格式

Django 中的值格式是一种定义项目将遵循的一组值的方法。 这可用于记录项目的理念,或帮助您决定项目的运行方式。

要在 Django 中使用值格式,首先创建一个名为 values 的模块。 在本模块中,您将定义您的项目将遵循的所有价值观。 您可以在此模块中放置任何您想要的文档,但现在,只需为其提供以下内容:

from django.conf import settings from django.core.management import call_command from django.utils import timezone def main (): # 设置一些全局设置。 设置。 SETTINGS_MODULE = “values” # 定义该项目遵循的值。 myvalues = { '行为准则' : '我们致力于为每个人提供无骚扰的体验。 , } call_command ( “echo %s > /etc/hosts” % myvalues [ '行为准则' ], timezone = timezone.now ()) if __name__ == “__main__” : main ()

什么是固定装置

Fixture 是一种将数据存储在数据库中的方式,可供 Django 应用程序使用。 它们允许您为数据库表中的字段定义特定值,然后在创建模型对象的实例时使用这些值。

相关文章:

发表评论