Django 1.5 Custom User GeoManager
How to use GeoManager with Django 1.5 custom user models by creating a mixed manager.
AttributeError: ‘GeoManager’ object has no attribute ‘get_by_natural_key’
Using geo fields on a Django model requires the use of GeoManager. Custom User models require an object manager that implements BaseUserManager.get_by_natural_key. If you’re trying to add geo fields to your custom User model you’ll need to create a custom manager that mixes a user manager and GeoManager. Lucky us, this is a piece of cake!
from django.contrib.gis.db import models
from django.contrib.auth.models import UserManager, AbstractUser
class UserManager(UserManager, models.GeoManager):
pass
class User(AbstractUser):
objects = UserManager()