class PostFactory(Factory):
    FACTORY_FOR = Post
title = 'My title'

@classmethod
def _prepare(cls, create, **kwargs):
    post = super(PostFactory, cls)._prepare(create, **kwargs)
if post.id:
    post.tags = Tag.objects.all()
return post
Библиотека Python factory_boy m2m в модели Django?