Let's say I have these Django models:
class State(Model):
name = CharField(max_length=2)
class Address(Model):
state = ForeignKey(State)
...
Would it be possible to create an Address factory where I could pass two letter strings to AddressFactory() for the state and the ForeignKey is automatically created?
I tried overriding __init__ for AddressFactory and that didn't work -- it wasn't called.
class AddressFactory(DjangoModelFactory):
def __init__(self, *args, **kwargs)
state = kwargs.get('state')
if isinstance(state, basestring):
kwargs['state'] = StateFactory(name=state)
super(AddressFactory, self).__init__(*args, **kwargs)
Besides it not working, I also see this has a problem with is StateFactory doesn't inherit the strategy, but I think you can see what I'm trying to accomplish?