aliaksei
aliaksei

Reputation: 734

Storing Location History in a Django Model Field

I am trying to store a multiple locations in a field of a django model, but I am not quite sure how to go about it. I am using GeoDjango's PointField to store the latest reported location.

class Tracker(models.Model):
    # Other fields..

    # srid 4326 is the WGS84 Spheroid used by GPS
    current_pos = models.PointField(editable=True, srid=4326)
    pos_hist = ?

I have looked at apps like django-field-history and similar, but they seem to be designed to allow changes to be reversed by admin/user, which I don't need.

Another method seems to be using a ForeignKey to make a many-to-many relationship to a Location model, but I can't seem to get my head around how that would work as each Tracker would have multiple Location models in that field, but there would be multiple Trackers?

Am I approaching this from the right direction or is there a better way? Thanks in advance!

Upvotes: 1

Views: 407

Answers (1)

bruno desthuilliers
bruno desthuilliers

Reputation: 77912

You definitly want a Location model with a ForeignKey on Tracker.

Note that this will not create a "many to many" relationship but a "one-to-many" one where a tracker has many locations and a location belong to one single tracker.

Upvotes: 2

Related Questions