If I have recipes like this:
org = Recipe('my.Organization',
active=True)org_unit = Recipe('my.OrganizationUnit',
organization=foreign_key(org),active=True)dept = Recipe('my.Department',
organization=foreign_key(org),
active=True)employee = Recipe('my.Employee',
organization=foreign_key(org),
org_unit=foreign_key(org_unit),
department=foreign_key(dept),active=True)
And I want to create an employee with an existing organization like this:
org = mommy.make_recipe('my.org')
# ... use org to create some other models which have nothing to do with employee ....
mommy.make_recipe('my.employee', organization=org)
I would like the org passed to the Employee recipe to be automagically passed into the creation of org_unit and dept. But in reality, they're not. Is there a different way to accomplish this. Otherwise, I'd have to basically make every receipt explicitly.
maybe
mommy.make_recipe('my.employee', organization=org, org_unit__organization=org, department__organization=org)
is what you're looking for.
[]'s
--
You received this message because you are subscribed to the Google Groups "Model Mommy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to model-mommy...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
class EmployeeFactory(factory.django.DjangoModelFactory):
class Meta:
model = models.Employee
first_name = u'Fédérée'
last_name = u'Employee'
active = True
organization = factory.SubFactory(OrganizationFactory)
org_unit = factory.SubFactory(OrganizationUnitFactory, organization=factory.SelfAttribute('..organization'))
department = factory.SubFactory(DepartmentFactory, organization=factory.SelfAttribute('..organization'))
dept = Recipe('my.Department',
organization=foreign_key(org),
active=True)employee = Recipe('my.Employee',
organization_set=related(dept_org)
)