I have a factory like so:
class PayInFactory(factory.DjangoModelFactory):
class Meta:
model = PayIn
@factory.lazy_attribute
def card(self):
if self.booking_payment and self.booking_payment.payment_type in [bkg_cts.PAYMENT_CARD, bkg_cts.PAYMENT_CARD_2X]:
factory.SubFactory(
CardFactory,
user=self.user,
)
I'm trying to generate a field card
only if the booking_payment
field has a payment_type
value in [bkg_cts.PAYMENT_CARD, bkg_cts.PAYMENT_CARD_2X]
The code goes into that statement but card field is empty after generation.
How can I do that properly ?
Is SubFactory
allowed in lazy_attribute
?
I'd like to be able to modify Card field from PayInFactory if possible like so:
>>> PayInFactory(card__user=some_user)
PostGeneration
won't do as I need this Card
to be available before the call to create. I overrided _create
and it may use the card if available.
Thanks !
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…