gregmuellegger/django-autofixture

How to generate random value from given list?

Closed this issue · 1 comments

Support I want to generate a car lists with random brand. But brands are from my given list.
Can I do that in your autofixture?

You can try using the ChoicesGenerator (https://github.com/gregmuellegger/django-autofixture/blob/master/autofixture/generators.py#L230), like this:

from models import YourCarModel
from autofixture import generators, register, AutoFixture

class YourCarModelAutoFixture(AutoFixture):
    field_values = {
        'brand': generators.ChoicesGenerator(values=your_list_of_brands),
    }

register(YourCarModel, MyModelAutoFixture)