Fabio
Fabio

Reputation: 1332

Django - Store user location data with GeoDjango

I want to use GeoDjango to get retrieve from the user location point information like city, country, etc. In order to use GeoDjango I have to install PostGIS which adds geographic object support to PostgreSQL.

Questions:

  1. Do I have to install PostGIS on the default database or is a best practice to store location data in different database?
  2. Can I mix django.db.models and django.contrib.gis.db.models to make clear difference between GeoDjango fields and the default ones?

Example:

from django.db import models
from django.contrib.gis.db import models as geo_models

class Profile(models.Model):
    """
    This model extends the `User` model as an One-To-One link.
    """
    user = models.OneToOneField(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    birth_date = models.DateField(null=True, blank=True)
    company_name = models.CharField(max_length=100, blank=True)

    location = geo_models.PointField()

Upvotes: 0

Views: 616

Answers (1)

AKX
AKX

Reputation: 169032

  1. The same database is fine (and makes things that much easier.)
  2. You can mix them. Same with the postgres contrib fields; you just use them where you need to.

And I know you didn't ask this, but if possible, it'll simplify things to use a custom user model instead of an one-to-one extension model like you've illustrated.

Upvotes: 3

Related Questions