I want to use Factory Boy and its support for Faker to generate strings from more than one provider. e.g. combining prefix
and name
:
# models.py
from django.db import models
class Person(models.Model):
full_name = models.CharField(max_length=255, blank=False, null=False)
# factories.py
import factory
class PersonFactory(factory.Factory):
class Meta:
model = models.Person
full_name = '{} {}'.format(factory.Faker('prefix'), factory.Faker('name'))
But this doesn't seem to work. e.g.:
>>> person = PersonFactory()
>>> person.full_name
'<factory.faker.Faker object at 0x7f25f4b09e10> <factory.faker.Faker object at 0x7f25f4ab74d0>'
What am I missing?
models.Person
class? This is relevant info. – Aixlachapelleprefix
and aname
class attribute that don't exist in your model and then combine them to createfull_name
. I'm not sure if this will cause an error, as your originalPerson
model doesn't have those fields. – Microfilm