当前位置: 首页>>代码示例>>Python>>正文


Python Employee.save方法代码示例

本文整理汇总了Python中models.Employee.save方法的典型用法代码示例。如果您正苦于以下问题:Python Employee.save方法的具体用法?Python Employee.save怎么用?Python Employee.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Employee的用法示例。


在下文中一共展示了Employee.save方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: save

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [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
开发者ID:wallacewy,项目名称:partime,代码行数:33,代码来源:forms.py

示例2: new_user

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [as 别名]
def new_user(request):
	use = User.objects.create_user(request.GET['username'],'',request.GET['pass'])
	use.last_name = request.GET['lname']
	use.first_name = request.GET['fname']
	use.save()
	new_date = datetime.date.today() - datetime.timedelta(days=1)
	e = Employee()
	e.user = use
	e.lastVoted = new_date
	e.save()
	user = authenticate(username=request.GET['username'],password=request.GET['pass'])
	login(request,user)
	return HttpResponseRedirect('/home/')
开发者ID:flexairconsultant,项目名称:gamereview,代码行数:15,代码来源:views.py

示例3: testPost

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [as 别名]
def testPost(request):
    print request
    if request.method == 'POST':
        reqName = request.POST['name']
        reqSubAreas = request.POST.getlist('subArea[]')
        reqSemester = request.POST['semester']
        reqAvailability = request.POST.getlist('availability[]')

        for x in Employee.SEMESTER_CHOICES:
            if reqSemester == x[1]:
                empObj = Employee(name=reqName, semester=x[0])

        empObj.save()

        for area in reqSubAreas:
            for x in Area.SUBAREA_CHOICES:
                if area == x[1]:
                    empObj.area_set.create(subarea=x[0])


        for availability in reqAvailability:
            timeArray = availability.split(" ")
            dayInput = timeArray[0]
            timeStartInput = timeArray[1] + " " + timeArray[2]
            timeEndInput = timeArray[3] + " " + timeArray[4]

            for day in Availability.DAY_CHOICES:
                if dayInput == day[1]:
                    reqDay = day[0]

            for time in Availability.TIME_CHOICES:
                if timeStartInput == time[1]:
                    reqTimeStart = time[0]
                if timeEndInput == time[1]:
                    reqTimeEnd = time[0]

            empObj.availability_set.create(day=reqDay, time_start=reqTimeStart, time_end=reqTimeEnd)

    return HttpResponse("name: " + reqName + 
                        "\nsubAreas: " + reqSubAreas[0] +
                        "\nsemester: " + reqSemester +
                        "\navailability: \n" + reqAvailability[0])
开发者ID:EFox2413,项目名称:scheduleApp,代码行数:44,代码来源:views.py

示例4: save_employees_to_database

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [as 别名]
def save_employees_to_database():
	alphabatized_employee_list = _retrieve_employee_data()

	for alphabet_set in alphabatized_employee_list:
		for employee in alphabet_set:
			if type(employee[1]) is dict:
				formatted_fields = _format_employee_fields(employee[1])
				if formatted_fields:
					new_employee = Employee(business_category=formatted_fields.get('business_category'),
											description=formatted_fields.get('description'),
											given_name=formatted_fields.get('given_name'),
											hire_date=formatted_fields.get('hire_date'),
											manager_name=formatted_fields.get('manager_name'),
											name=formatted_fields.get('name'),
											office_name=formatted_fields.get('office_name'),
											# picture=formatted_fields.get('picture'),
											title=formatted_fields.get('title'),
											user_name=formatted_fields.get('user_name'))
					
					try:
						Employee.objects.get(name=new_employee.name)
					except:
						new_employee.save()
开发者ID:unzunz,项目名称:Varys,代码行数:25,代码来源:import_employee_data.py

示例5: save

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [as 别名]
    def save(self):
        employee_id = self.employee_id
        position_id = self.position_id
        person_model = models.get_model('demo', 'Person')
        position_model = models.get_model('positions', 'Position')

        try:
            new_employee = Employee(
                employee=person_model.objects.get(pk=employee_id),
                position=position_model.objects.get(pk=position_id),
            )
        except person_model.DoesNotExist:
            print "Trying to add employee_id that doesn't exist"
        except position_model.DoesNotExist:
            print "Trying to add position_id that doesn't exist"


        try:
            old_employee = Employee.objects.get(employee=new_employee.employee)
        except Employee.DoesNotExist:
            new_employee.save()
        else:
            old_employee.position = new_employee.position
            old_employee.save()
开发者ID:sadykovildar,项目名称:bars_m3_blank,代码行数:26,代码来源:proxy.py

示例6: test_custom_pk

# 需要导入模块: from models import Employee [as 别名]
# 或者: from models.Employee import save [as 别名]
    def test_custom_pk(self):
        dan = Employee(employee_code=123, first_name='Dan', last_name='Jones')
        dan.save()
        self.assertQuerysetEqual(Employee.objects.all(),
                                 ['<Employee: Dan Jones>'])

        fran = Employee(employee_code=456, first_name='Fran', last_name='Bones')
        fran.save()
        self.assertQuerysetEqual(Employee.objects.all(),
                                 ['<Employee: Fran Bones>', '<Employee: Dan Jones>'])

        self.assertEqual(repr(Employee.objects.get(pk=123)),
                         '<Employee: Dan Jones>')
        self.assertEqual(repr(Employee.objects.get(pk=456)),
                         '<Employee: Fran Bones>')

        self.assertRaises(Employee.DoesNotExist,
                          Employee.objects.get, pk=42)

        # Use the name of the primary key, rather than pk.
        self.assertEqual(repr(Employee.objects.get(employee_code__exact=123)),
                         '<Employee: Dan Jones>')

        # pk can be used as a substitute for the primary key.
        self.assertQuerysetEqual(Employee.objects.filter(pk__in=[123, 456]),
                                 ['<Employee: Fran Bones>', '<Employee: Dan Jones>'])

        # The primary key can be accessed via the pk property on the model.
        e = Employee.objects.get(pk=123)
        self.assertEqual(e.pk, 123)

        # Or we can use the real attribute name for the primary key:
        self.assertEqual(e.employee_code, 123)

        # Fran got married and changed her last name.
        fran = Employee.objects.get(pk=456)
        fran.last_name = 'Jones'
        fran.save()

        self.assertQuerysetEqual(Employee.objects.filter(last_name__exact='Jones') ,
                                 ['<Employee: Dan Jones>', '<Employee: Fran Jones>'])

        emps = Employee.objects.in_bulk([123, 456])
        self.assertEqual(repr(emps[123]),
                         '<Employee: Dan Jones>')


        b = Business(name='Sears')
        b.save()
        b.employees.add(dan, fran)
        self.assertQuerysetEqual(b.employees.all(),
                                 ['<Employee: Dan Jones>', '<Employee: Fran Jones>'])
        self.assertQuerysetEqual(fran.business_set.all(),
                                 ['<Business: Sears>'])
        self.assertEqual(repr(Business.objects.in_bulk(['Sears'])),
                         "{u'Sears': <Business: Sears>}")

        self.assertQuerysetEqual(Business.objects.filter(name__exact='Sears'),
                                 ['<Business: Sears>'])
        self.assertQuerysetEqual(Business.objects.filter(pk='Sears'),
                                 ['<Business: Sears>'])

        # Queries across tables, involving primary key
        self.assertQuerysetEqual(Employee.objects.filter(business__name__exact='Sears'),
                                 ['<Employee: Dan Jones>', '<Employee: Fran Jones>'])
        self.assertQuerysetEqual(Employee.objects.filter(business__pk='Sears'),
                                 ['<Employee: Dan Jones>', '<Employee: Fran Jones>'])

        self.assertQuerysetEqual(Business.objects.filter(employees__employee_code__exact=123),
                                 ['<Business: Sears>'])
        self.assertQuerysetEqual(Business.objects.filter(employees__pk=123),
                                 ['<Business: Sears>'])
        self.assertQuerysetEqual(Business.objects.filter(employees__first_name__startswith='Fran'),
                                 ['<Business: Sears>'])
开发者ID:Leveofan,项目名称:django-old,代码行数:76,代码来源:tests.py


注:本文中的models.Employee.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。