I want to get x
and y
coordinates from the point in the following queryset
:
user = User.objects.values('id', 'email', 'username', 'point').first()
These are my models
:
from django.db.models import Model
from django.contrib.gis.db.models import PointField
class BasePointModel(Model):
point = PointField(null=True, spatial_index=True, geography=True)
class Meta:
abstract = True
class User(AbstractUser, BasePointModel, HashableModel): # type: ignore
# First Name and Last Name do not cover name patterns
# around the globe.
name = CharField(_("Name of User"), blank=True, max_length=255)
is_online = BooleanField(_("Is online"), default=False)
I am getting the following result:
{'id': 85270,
'email': 'username_0@email.com',
'username': 'username_0',
'point': <Point object at 0x7f8e061cc2b8>}
How can I get an x
and y
, making a queryset with values
?
I want to get something like this:
{'id': 85270,
'email': 'username_0@email.com',
'username': 'username_0',
'point__x': '-4.266398314110177',
'point__y': '-39.39432682357033'}
I make requests that return 50,000 lines from a database, and I notice that performance is getting worse due to data serialization. I want to minimize serialization by returning values
.
But the PointField
always returns an object
, and I still haven't found a way to serialize it in the best way.