本文整理汇总了Python中class_fixtures.models.Fixture.o2o方法的典型用法代码示例。如果您正苦于以下问题:Python Fixture.o2o方法的具体用法?Python Fixture.o2o怎么用?Python Fixture.o2o使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类class_fixtures.models.Fixture
的用法示例。
在下文中一共展示了Fixture.o2o方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_two_level_fk_o2o_hierarchy_mixed
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import o2o [as 别名]
def test_two_level_fk_o2o_hierarchy_mixed(self):
# FK from Employee to Company, O2O from EmployeeHistory to Employee
company_fixture = Fixture(Company)
company_fixture.add(1, name='Macrohard')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=company_fixture.fk(1), manager=None)
history_fixture = Fixture(EmployeeHistory)
history_fixture.add(1, employee=employee_fixture.o2o(1), date_joined='2007-02-22')
# Load in mixed order: 3rd, 1st, 2nd level
history_fixture.load()
self.assertEqual(Company.objects.count(), 1)
self.assertEqual(Employee.objects.count(), 1)
self.assertEqual(EmployeeHistory.objects.count(), 1)
示例2: test_o2o_relation
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import o2o [as 别名]
def test_o2o_relation(self):
company_fixture = Fixture(Company)
company_fixture.add(1, name='Macrohard')
employee_fixture = Fixture(Employee)
employee_fixture.add(1, name='Andy Depressant', company=company_fixture.fk(1), manager=None)
history_fixture = Fixture(EmployeeHistory)
history_fixture.add(1, employee=employee_fixture.o2o(1), date_joined='2007-02-22')
company_fixture.load()
employee_fixture.load()
history_fixture.load()
self.assertEqual(Company.objects.count(), 1)
self.assertEqual(Employee.objects.count(), 1)
self.assertEqual(EmployeeHistory.objects.count(), 1)
self.assertEqual(Employee.objects.all()[0].employeehistory, EmployeeHistory.objects.all()[0])
示例3: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import o2o [as 别名]
from class_fixtures.models import Fixture
from class_fixtures.tests.models import Company, Employee, EmployeeHistory
company_fixture = Fixture(Company)
employee_fixture = Fixture(Employee)
employee_history_fixture = Fixture(EmployeeHistory)
company_fixture.add(3, name="Dewey, Cheatem & Howe")
employee_fixture.add(5, name="Sly M. Ball", company=company_fixture.fk(3))
employee_fixture.add(6, name="Mei Ting", company=company_fixture.fk(3), manager=employee_fixture.fk(5))
employee_history_fixture.add(5, employee=employee_fixture.o2o(5), date_joined="2000-11-03")
employee_history_fixture.add(6, employee=employee_fixture.o2o(6), date_joined="1985-12-28")
示例4: Fixture
# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import o2o [as 别名]
membership_fixture.add(
8,
musician=musician_fixture.fk(5),
band=metalband_fixture.fk(6),
date_joined="1982-03-03",
instrument="Guitarrrr-ahh",
)
# Single M2M addition with a kwarg
roadie_fixture.add(3, name="Tats Brimhat", hauls_for=[band_fixture.m2m(5)])
# Two M2M additions with a list of kwargs
roadie_fixture.add(4, name="Blackie Teeshirt", hauls_for=[band_fixture.m2m(5), metalband_fixture.m2m(6)])
# Single M2M addition with a relation token
roadie_fixture.add(5, name="Ciggy Tardust", hauls_for=[metalband_fixture.m2m(6)])
company_fixture = Fixture(Company)
employee_fixture = Fixture(Employee)
employee_history_fixture = Fixture(EmployeeHistory)
company_fixture.add(2, name="FacelessCorp Inc.")
# Normal FK relationship to another model
employee_fixture.add(3, name="Ty Rant", company=company_fixture.fk(2))
# Same, plus a recursive FK relationship to self
employee_fixture.add(4, name="Sue Ecide-Risk", company=company_fixture.fk(2), manager=employee_fixture.fk(3))
# OneToOne
employee_history_fixture.add(3, employee=employee_fixture.o2o(3), date_joined="2003-03-15")
employee_history_fixture.add(4, employee=employee_fixture.o2o(4), date_joined="2006-08-07")