Does anyone know how to create the factory in factoryboy based on this models.py
class Halte(models.Model):
koppel_halte1 = models.ForeignKey('self',
related_name='koppel_halteA',
verbose_name="Koppel Halte",
help_text="geef hier een gekoppelde halte aan",
null=True, blank=True)
koppel_halte2 = models.ForeignKey('self',
related_name='koppel_halteB',
verbose_name="Koppel Halte",
help_text="geef hier een gekoppelde halte aan",
null=True, blank=True)
Notice the 'self'? (And YES this type of relation is necesarry.)
I have tried several things in FactoryBoy (SubFactory, RelatedFactory, SelfAtribute, PostGeneration) but I can't get it to work.
one of the attempts in a factories.py
class HalteFactoryA(factory.DjangoModelFactory):
class Meta:
model = models.Halte
class HalteFactoryB(factory.DjangoModelFactory):
class Meta:
model = models.Halte
class HalteFactory(factory.DjangoModelFactory):
class Meta:
model = models.Halte
# todo: how to do this?? (see models.Halte)
koppel_halte1 = factory.RelatedFactory(HalteFactoryA)
koppel_halte2 = factory.RelatedFactory(HalteFactoryB)
Any advice?
Thank you.