Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

save a tuple to a django model

Is there a way to save a tuple to a django model?

example:

Class User(models.Model):
  location = models.tupleField()

where User.location = (longitude, latitude)

like image 714
mabdrabo Avatar asked Dec 16 '22 02:12

mabdrabo


2 Answers

Maybe you are looking for GeoDjango's PointField:

from django.contrib.gis.db import models

Class User(models.Model):
    location = models.PointField(help_text="Represented as (longitude, latitude)”)
like image 108
Norbert Sebők Avatar answered Dec 17 '22 14:12

Norbert Sebők


Honestly, i didn't see tupleField in django documentation. I think better approach is add two fields longitude and latitude or create another model to store location and in User model add ForeignKey.

like image 39
ASmith78 Avatar answered Dec 17 '22 15:12

ASmith78