0

I have three classes.In OrdFactory i wana pass only id to "sku" field and sku is integer field.

class CoFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = models.Co

    name = factory.Sequence(lambda n: 'Co {}'.format(n))

class CrFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = models.Cr

    name = factory.Sequence(lambda n: 'Cr {}'.format(n))

class OrdFactory(factory.django.DjangoModelFactory):

    class Meta:
        model = models.Ord

    sku = random.choice([factory.SubFactory(CrFactory), factory.SubFactory(CoFactory)])
    quantity = 75.6

I am getting following error.

int() argument must be a string, a bytes-like object or a number, not 'Co'.

I have tried using id also:-

sku = random.choice([factory.SubFactory(CrFactory).id, factory.SubFactory(CoFactory).id])

but this also throwing error.

wfehr
  • 2,185
  • 10
  • 21
Arvind Kumar
  • 259
  • 4
  • 15

1 Answers1

1

I have fixed using trait.Overload is also a alternative solution. https://factoryboy.readthedocs.io/en/latest/reference.html#factory.Trait

Arvind Kumar
  • 259
  • 4
  • 15