I have a Django Model defined like below:
class CustomModel(models.Model):
column = models.CharField(max_length=50, unique=True)
Define a Factory for the model
from factory_boy import DjangoModelFactory
class CustomModelFactory(DjangoModelFactory):
column = 'V1'
FACTORY_FOR = CustomModelFactory()
How do i make sure that factory implements get_or_create instead of a create everytime?
Does anyone know how can this be done?
The way to implement this is by structuring your Factory class as follow:
class CustomModelFactory(DjangoModelFactory):
class Meta:
django_get_or_create = ('column',)
column = 'V1'
FACTORY_FOR = CustomModel