已解決:燈具的 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 應用程序使用。 它們允許您為數據庫表中的字段定義特定值,然後在創建模型對象的實例時使用這些值。

相關文章:

發表評論