Q:

How to store Users' Location in a Django/Postgres Application

I am developing a Phone app which sends a user's location to the backend every time the app is opened. 
My goal is to store as much location data for the user as possible so I can do some machine learning to calculate which posts in their normal area of movement every day will pertain most to them.
I use GeoDjango and PostGis to make the application location-aware, and am struggling to determine which data structure in the database will best fit this scenario.
The question comes down to whether I should give each user a location = pg_fields.ArrayField() attribute which will end up being extremely large, or use location=models.ManyToManyField(UserLocation). I know toast tables are an issue in Postgres with large arrays, but are they a big enough issue where it would not be worth the stress when trying to extract the data for the user when running machine learning algorithms?

A:

Save your location data in its own model:
class UserLocation(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, ...)
    recorded_at = models.DateTimeField()  # time recoreded on phone
    created_at = models.DateTimeField(auto_now_add=True)  # time saved on db
    location =  models.PointField()
    accuracy = models.IntegerField() # meters, rounded up
    altitude = models.IntegerField(null=True, blank=True) # meters, rounded
    # more info... IP, phone type, phone id, session id, app version etc.

