klen / mixer

Mixer -- Is a fixtures replacement. Supported Django, Flask, SqlAlchemy and custom python objects.
Other
939 stars 96 forks source link

Generate model instance with related data at once. #123

Open AlwxSin opened 5 years ago

AlwxSin commented 5 years ago

Thanks for the great library.

Is there an api to generate a model instance with several relations (OneToOne, ManyToOne, ManyToMany)? Like so:

user = mixer.blend(User)
    .with(Profile, 1)  # one profile
    .with(Post, 4)   # 4 posts
    .with(Comment, 20, post=mixer.mix.posts)  # 20 comments to previous posts