python - Factory Boy subfactory over 'self' -


does know how create factory in factoryboy based on 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 'self'? (and yes type of relation necesarry.)

i have tried several things in factoryboy (subfactory, relatedfactory, selfatribute, postgeneration) can't work.

one of attempts in 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 this?? (see models.halte)     koppel_halte1 = factory.relatedfactory(haltefactorya)     koppel_halte2 = factory.relatedfactory(haltefactoryb) 

any advice?

thank you.

@bakkal has right, important missing factor target recursion depth must specified, stated in issue: https://github.com/rbarrois/factory_boy/issues/173

# myproj/myapp/factories.py class mymodelfactory(factory.factory):     class meta:         model = models.mymodel     parent = factory.subfactory('myapp.factories.mymodelfactory') 

then recursion max depth needs added, or infinite depth reached error (as noted @sjoerd van poelgeest in comments):

m = mymodelfactory(parent__parent__parent__parent=none) 

in case allowing depth of 3 being created, , last 1 have null parent.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -