Given the following state:
class Album(models.Model):
thumb = models.ForeignKey('Image', related_name='image')
class Image(models.Model):
album = models.ForeignKey('Album', null=True, blank=True)
with factory_boy:
class AlbumFactory(factory.DjangoModelFactory):
FACTORY_FOR = 'app.Album'
thumb = factory.SubFactory(
'path.to.factories.ImageFactory'
)
class ImageFactory(factory.DjangoModelFactory):
FACTORY_FOR = 'app.Image'
album = factory.RelatedFactory(AlbumFactory, 'thumb')