python - python 如何为工厂男孩指定数据库?

  显示原文与译文双语对照的内容
145 3

FactoryBoy似乎总是在默认数据库中创建实例。 但我有以下问题。


cpses = CanonPerson.objects.filter(persons__vpd=6,


 persons__country="United States").using("global")



代码指向 global 数据库。 我没有找到在工厂内指定数据库的方法:


class CanonPersonFactory(django_factory.DjangoModelFactory):


 class Meta:


 model = CanonPerson


 django_get_or_create = ('name_first', 'p_id')


 p_id = 1


 name_first = factory.Sequence(lambda n:"name_first #%s" % n)



 @factory.post_generation


 def persons(self, create, extracted, **kwargs):


 if not create:


 # Simple build, do nothing.


 return



 if extracted:


 # A list of groups were passed in, use them


 for person in extracted:


 self.persons.add(person)



时间: 原作者:

...