factory_boy allows you to define attributes as sequences, e.g.:
class MyFactory(factory.Factory):
id = factory.Sequence(lambda n: "ID%s" % n)
By default, the sequence type is a str
.
However if you want to do some trickier formatting you can use the type
keyword.
So to get "ORD000", "ORD001", etc. sequence:
class OrderFactory(factory.Factory):
id = factory.Sequence(lambda n: "ID%03d" % n, type=int)