[Answered ]-Postgres select function in Django annotation

1πŸ‘

βœ…

You can create a custom function using Expressions.

class GeoX(Func):
    function = 'X'

MyModel.objects.annotate(x=GeoX('field'))

This will result in the geometry X function being invoked and it’s result being annotated to a field labeled x in your model. However this is the inferior solution. The better solution is to install geodjango. That provides full access to almost every single function in PostGIS. Also works with spatialite and msyql spatial extensions.

πŸ‘€e4c5

1πŸ‘

I managed to solve problem using Func()

Func(F('geometry'), function='x')
πŸ‘€Crystal

Leave a comment