abolotnov
abolotnov

Reputation: 4332

setting up django_auth_ldap to populate user profile

I'm trying to configure django_ldap_auth to populate user profile with their region data from LDAP:

I created a model for the profile:

from django.db import models
from django.contrib.auth.models import User
class profile(models.Model):
    user = models.ForeignKey(User, unique=True)
    region = models.CharField(max_length=128, null=True, blank=True)

    def __unicode__(self):
        return '{0} profile'.format(self.user.username)

    class Meta:
        app_label = 'core'

I configured my settings to map to 'l' LDAP attribute (that's how region is marked in LDAP)

AUTH_PROFILE_MODULE = 'core.profile'
 AUTH_LDAP_PROFILE_ATTR_MAP = {"region": "l"}

This may be important, the profile class sits inside app/models/UserProfile.py file and models/init.py has from UserProfile import profile statement.

However, I still get the following message in debug and profile won't populate:

search_s('dc=*****,dc=ru', 2, '(sAMAccountName=******)') returned 1 objects: CN=Болотнов Александр,OU=****,OU=****,DC=***,DC=ru
Populating Django user *****
Django user **** does not have a profile to populate

Is there anything I'm missing? userdata such as first/last name and email populate just fine but region won't.

Upvotes: 2

Views: 3312

Answers (1)

psagers
psagers

Reputation: 859

This means that this particular User object does not have an associated profile object. Django does not automatically create profile objects, nor does django-auth-ldap. Typically, you will install a post_save signal handler on the User model to create profiles.

See https://docs.djangoproject.com/en/1.4/topics/auth/#storing-additional-information-about-users.

Upvotes: 3

Related Questions