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


Python Fixture.o2o方法代码示例

本文整理汇总了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)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:15,代码来源:tests_loaddata.py

示例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])
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:16,代码来源:tests_loaddata.py

示例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")
开发者ID:jklaiho,项目名称:django-class-fixtures,代码行数:14,代码来源:some_fixtures.py

示例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")
开发者ID:jklaiho,项目名称:django-class-fixtures,代码行数:32,代码来源:other_fixtures.py


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