gregmuellegger / django-autofixture

Can create auto-generated test data.
BSD 3-Clause "New" or "Revised" License
460 stars 118 forks source link

How to generate random value from given list? #98

Closed elcolie closed 7 years ago

elcolie commented 7 years ago

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?

gregmuellegger commented 7 years ago

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)