0
私はDjango 1.11とPython 3を使用しています。現在、私は自分のLDAP認証を使用しています。しかし、私は自分のユーザーモデルを拡張したいのですが、私は自分のユーザーモデルを拡張しようとすると次のエラーが発生します。ユーザモデルを拡張する際の属性エラー
AttributeError: 'User' object has no attribute 'profile'
[25/Oct/2017 14:47:28] "POST /account/login/ HTTP/1.1" 500 224535
私はuser.profileまたはuser.AllEeActiveするために私のコードを変更しようとしましたが、その後、それは私に次のエラーを与える:
以下File "C:\python\security\accounts\models.py", line 52, in save_user_profile
instance.username.save()
AttributeError: 'str' object has no attribute 'save'
[25/Oct/2017 14:43:31] "POST /account/login/ HTTP/1.1" 500 224521
は、私が何をやっている、私のmodels.pyです間違っている?
from __future__ import unicode_literals
from django.contrib.auth.models import User
from django.db import models
from django.forms import ModelForm
from django.db.models.signals import post_save
from django.dispatch import receiver
import django_filters
class AllEeActive(models.Model):
employee_ntname = models.OneToOneField(User, db_column='Employee_NTName',max_length=12) # 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.
@receiver(post_save, sender=User)
def create_user_profile(sender, instance, created, **kwargs):
if created:
AllEeActive.objects.create(user=instance)
@receiver(post_save, sender=User)
def save_user_profile(sender, instance, **kwargs):
instance.profile.save()
class Meta:
managed = False
def __str__(self):
return self.employee_ntname