Since the type of a generic foreign key object is not know until a record is created in the model, what sub factory do I define it as ? Or is there another way to approach this ?
models.py
class Contract(models.Model):
offer_type = models.ForeignKey(ContentType, on_delete=models.PROTECT)
offer_id = models.PositiveIntegerField()
offer = GenericForeignKey('offer_type', 'offer_id')
invoice = models.ForeignKey('Invoice', on_delete=models.PROTECT)
status = models.CharField(max_length=8)
commission = models.DecimalField(max_digits=100, decimal_places=2)
factories.py
class ContractFactory(factory.DjangoModelFactory):
class Meta:
model = models.Contract
#What to do here ???
offer = factory.SubFactory(????)
invoice = factory.SubFactory(InvoiceFactory)
status = 'active'
commission = 40.00