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


Python Fixture.m2m方法代码示例

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


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

示例1: test_multiple_m2m_relations

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
 def test_multiple_m2m_relations(self):
     band_fixture = Fixture(Band)
     band_fixture.add(1, name="Nuns N' Hoses")
     band_fixture.add(2, name='Led Dirigible')
     roadie_fixture = Fixture(Roadie)
     roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
     band_fixture.load()
     roadie_fixture.load()
     self.assertEqual(Band.objects.count(), 2)
     self.assertEqual(Roadie.objects.count(), 1)
     self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 2)
     self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
     self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:15,代码来源:tests_loaddata.py

示例2: test_m2m_dependent_first

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
 def test_m2m_dependent_first(self):
     # The above FK tests already apply to explicit "through" M2Ms, so this
     # only tests normal, "non-through" ones.
     band_fixture = Fixture(Band)
     band_fixture.add(1, name="Nuns N' Hoses")
     band_fixture.add(2, name='Led Dirigible')
     roadie_fixture = Fixture(Roadie)
     roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
     # M2M relations are two-way, but like only one end has the
     # ManyToManyField, the fixture dependency is also defined in one end
     # of the relation. roadie_fixture is the dependent here, load it first
     # to test proper dependency resolution.
     roadie_fixture.load()
     self.assertEqual(Band.objects.count(), 2)
     self.assertEqual(Roadie.objects.count(), 1)
     self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.count(), 2)
     self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.count(), 1)
     self.assertEqual(Band.objects.get(name='Led Dirigible').roadie_set.count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:20,代码来源:tests_loaddata.py

示例3: test_reverse_single_m2m_relation

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
 def test_reverse_single_m2m_relation(self):
     roadie_fixture = Fixture(Roadie)
     roadie_fixture.add(1, name='Marshall Amp')
     band_fixture = Fixture(Band)
     band_fixture.add(1, name="Nuns N' Hoses", roadie_set=[roadie_fixture.m2m(1)])
     roadie_fixture.load()
     band_fixture.load()
     self.assertEqual(Band.objects.count(), 1)
     self.assertEqual(Roadie.objects.count(), 1)
     self.assertEqual(Roadie.objects.get(name='Marshall Amp').hauls_for.filter(name="Nuns N' Hoses").count(), 1)
     self.assertEqual(Band.objects.get(name="Nuns N' Hoses").roadie_set.filter(name='Marshall Amp').count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:13,代码来源:tests_loaddata.py

示例4: test_alternate_database

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
 def test_alternate_database(self):
     """
     Explicitly assign fixtures to a non-default database.
     """
     if self.do_tests:
         band_fixture = Fixture(Band)
         band_fixture.add(1, name="Nuns N' Hoses")
         band_fixture.add(2, name='Led Dirigible')
         roadie_fixture = Fixture(Roadie)
         roadie_fixture.add(1, name='Marshall Amp', hauls_for=[band_fixture.m2m(1), band_fixture.m2m(2)])
         call_command('loaddata', band_fixture, roadie_fixture, database='alternate', verbosity=0)
         self.assertEqual(Band.objects.using('alternate').count(), 2)
         self.assertEqual(Roadie.objects.using('alternate').count(), 1)
         self.assertEqual(Band.objects.count(), 0)
         self.assertEqual(Roadie.objects.count(), 0)
         self.assertEqual(Roadie.objects.using('alternate').get(name='Marshall Amp').hauls_for.count(), 2)
         self.assertEqual(Band.objects.using('alternate').get(name="Nuns N' Hoses").roadie_set.count(), 1)
         self.assertEqual(Band.objects.using('alternate').get(name='Led Dirigible').roadie_set.count(), 1)
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:20,代码来源:tests_loaddata.py

示例5: Fixture

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
# Keyword-based FK target lookup
membership_fixture.add(
    7, musician=musician_fixture.fk(6), band=band_fixture.fk(5), date_joined="2000-04-01", instrument="All of them"
)

# Relation token -based FK target lookup
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))
开发者ID:jklaiho,项目名称:django-class-fixtures,代码行数:33,代码来源:other_fixtures.py

示例6: test_non_iterable_m2m_definition

# 需要导入模块: from class_fixtures.models import Fixture [as 别名]
# 或者: from class_fixtures.models.Fixture import m2m [as 别名]
 def test_non_iterable_m2m_definition(self):
     band_fixture = Fixture(Band)
     band_fixture.add(1, name="Nuns N' Hoses")
     roadie_fixture = Fixture(Roadie)
     # hauls_for requires a one-item iterable
     self.assertRaises(FixtureUsageError, roadie_fixture.add, 1, name='Marshall Amp', hauls_for=band_fixture.m2m(1))
开发者ID:brantc,项目名称:django-class-fixtures,代码行数:8,代码来源:tests_loaddata.py


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