LDAP Authentication: Extending User Model to an existing table

78 views
Skip to first unread message

Nick Hoff

unread,
Oct 24, 2017, 7:57:10 PM10/24/17
to Django users

I'm currently using 'django_python3_ldap.auth.LDAPBackend' with Django 1.9 and Python 3, which I have working correctly were a user authenticates with their network login / password then a user is created in the data base with username, password, email, first_name, and last_name, user_created_at all extracted from LDAP, which is what I want to stay the same.

Now The network login is the username in the auth_user table. I have another table, which stores user information with a field titled employee_ntname, the table below is a pre-existing table in the database which can not be changed or updated for this use case.

class AllEeActive(models.Model):

employee_ntname = models.CharField(db_column='Employee_NTName',max_length=50)  # Field name made lowercase.
employee_last_name = models.CharField(db_column='Employee_Last_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.
employee_first_name = models.CharField(db_column='Employee_First_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.
b_level = models.CharField(db_column='B_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.
group_name = models.CharField(db_column='Group_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.
r_level = models.CharField(db_column='R_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.
division_name = models.CharField(db_column='Division_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.
d_level = models.CharField(db_column='D_Level', max_length=10, blank=True, null=True)  # Field name made lowercase.
market_name = models.CharField(db_column='Market_Name', max_length=100, blank=True, null=True)  # Field name made lowercase.
coid = models.CharField(db_column='COID', max_length=50, blank=True, null=True)  # Field name made lowercase.
unit_no = models.CharField(db_column='Unit_No', max_length=50, blank=True, null=True)  # Field name made lowercase.
dept_no = models.CharField(db_column='Dept_No', max_length=50, blank=True, null=True)  # Field name made lowercase.
department_desc = models.CharField(db_column='Department_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.
employee_status = models.CharField(db_column='Employee_Status', max_length=50, blank=True, null=True)  # Field name made lowercase.
job_desc = models.CharField(db_column='Job_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.
position_desc = models.CharField(db_column='Position_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.
supervisor_last_name = models.CharField(db_column='Supervisor_Last_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.
supervisor_first_name = models.CharField(db_column='Supervisor_First_Name', max_length=50, blank=True, null=True)  # Field name made lowercase.
supervisor_job_desc = models.CharField(db_column='Supervisor_Job_Desc', max_length=50, blank=True, null=True)  # Field name made lowercase.
cfo = models.CharField(db_column='CFO', max_length=255, blank=True, null=True)  # Field name made lowercase.
email_address = models.CharField(db_column='Email_Address', max_length=250, blank=True, null=True)  # Field name made lowercase.
location_code = models.CharField(db_column='Location_Code', max_length=20, blank=True, null=True)  # Field name made lowercase.
location_code_desc = models.CharField(db_column='Location_Code_Desc', max_length=255, blank=True, null=True)  # Field name made lowercase.
corporate_flag = models.CharField(db_column='Corporate_Flag', max_length=1, blank=True, null=True)  # Field name made lowercase.
hire_date = models.DateTimeField(db_column='Hire_Date', blank=True, null=True)  # Field name made lowercase.
termination_date = models.DateTimeField(db_column='Termination_Date', blank=True, null=True)  # Field name made lowercase.
employee_status_id = models.IntegerField(db_column='Employee_Status_ID', blank=True, null=True)  # Field name made lowercase.
qv_statusid = models.IntegerField(db_column='QV_StatusID', blank=True, null=True)  # Field name made lowercase.
lawson_status_id = models.IntegerField(db_column='Lawson_Status_ID', blank=True, null=True)  # Field name made lowercase.
load_date = models.DateTimeField(db_column='Load_Date', blank=True, null=True)  # Field name made lowercase.

class Meta:
    managed = False


def __str__(self):
    return self.employee_ntname

I've attempted to use AbstractUser and AUTH_USER_MODEL = 'accounts.AllEeActive', but haven't been able to get it to work correctly to write to the auth_user table in my SQL database. Any ideas as to how to get my username associated with the employee_ntname so when I use a form with both fields on it all them are populated as a one to one relationship?

Tyler Rudie

unread,
Nov 25, 2017, 10:49:58 AM11/25/17
to Django users
I would look into using the one-to-one link between the objects

Reply all
Reply to author
Forward
0 new messages