I need to create some fake data using factory boy
. I have the following model:
class Fabric(models.Model):
title = models.CharField(max_length=200, blank=True)
description = models.CharField(max_length=200, blank=True)
price = models.DecimalField(decimal_places=2, max_digits=10, null=True, blank=False)
I need to create a factory based on this model, and I would like the price to have a random value between 1 and 100.
class FabricFactory(DjangoModelFactory):
class Meta:
model = Fabric
title = factory.Faker('name')
description = factory.Faker('catch_phrase')
price = random.randrange(MIN_PRICE, MAX_PRICE + 1)
The problem with this is that I am always getting the same price for every instance.
factory_boy
) it is a fixture, that gets reused, it seems it's only being instantiated once and the scope of this fixture is your whole session. is there any way to modify the scope of your fixture withinfactory_boy
? – Oasis