klen/mixer

Way to alter "magic" fieldname-based logic

MarSoft opened this issue · 2 comments

I have a model User with a field named name. But that field represent user login, so it should not contain whitespaces and dots. So values like Dr. John Smith do not fit.
Which is the "good" way to achieve this?
From documentation I found a Mixer.register method. But if I create a function, how could I use Mixer's internals to generate a "good" fake value?

Partial answer to my question is to create own Faker instance and use its methods:

faker = Faker()
mixer.register(models.User, name=faker.user_name, ...)
klen commented

That's true. Also you can use custom factory:

    class MyFactory(GenFactory):
        fakers = {
            ('name', str): faker.user_name
        }

    mixer = Mixer(factory=MyFactory)