How to generate random value from given list?
Closed this issue · 1 comments
elcolie commented
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
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)