本文整理汇总了Python中models.Employee.set_user方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.set_user方法的具体用法?Python Employee.set_user怎么用?Python Employee.set_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Employee
的用法示例。
在下文中一共展示了Employee.set_user方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: save
# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import set_user [as 别名]
def save(self, role='R'):
user = User(username=self.cleaned_data["username"])
user.set_password(self.cleaned_data["password1"])
user.email = User.objects.normalize_email(self.cleaned_data["email"])
user.save()
full_name = self.cleaned_data["full_name"]
gender = self.cleaned_data["gender"]
age = self.cleaned_data["age"]
location = self.cleaned_data["location"]
if role == 'R':
permission = Permission.objects.get(codename__exact='add_request')
employee_type = self.cleaned_data["type"]
nationality = self.cleaned_data["nationality"]
emp_model = Employee(full_name=full_name, gender=gender, age=age, location=location,
type=employee_type, nationality=nationality)
else:
permission = Permission.objects.get(codename__exact='add_offer')
employer_type = self.cleaned_data["employer_type"]
emp_model = Employer(full_name=full_name, gender=gender, age=age, location=location,
type=employer_type)
user.user_permissions.add(permission)
emp_model.set_user(user)
emp_model.save()
skills_text = self.cleaned_data["skills_text"]
if len(skills_text.strip()) > 0:
for skill_name in skills_text.split("\r\n"):
if len(skill_name.strip()) > 0:
skill, created = Skill.objects.get_or_create(name=skill_name)
EmployeeSkills.objects.create(employee=emp_model, skill=skill)
return user