我正在尝试使用Factory Boy创建一些数据,但我在OrderFactory example of the Factory Boy index page中使用model__key
时遇到问题。
这是我的工厂:
class UserFactory(DjangoModelFactory):
class Meta:
model = 'auth.User'
django_get_or_create = ('username',)
username = 'user'
class EntityFactory(DjangoModelFactory):
class Meta:
model = 'app.Entity'
user = SubFactory(UserFactory)
这就是我正在尝试的:
EntityFactory(user__username='admin')
但我得到了:
TypeError: 'user__username' is an invalid keyword argument for this function
注入实际实例:
admin = UserFactory(username='admin')
EntityFactory(user=admin)
谢谢!